Bird
Raised Fist0
Denoframework~20 mins

KV on Deno Deploy - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deno KV Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this Deno KV code snippet?

Consider this code running on Deno Deploy with KV enabled:

const kv = await Deno.openKv();
await kv.set(["user", "123"], { name: "Alice", age: 30 });
const result = await kv.get(["user", "123"]);
console.log(result.value?.name);

What will be printed in the console?

Deno
const kv = await Deno.openKv();
await kv.set(["user", "123"], { name: "Alice", age: 30 });
const result = await kv.get(["user", "123"]);
console.log(result.value?.name);
Anull
Bundefined
CAlice
DThrows a runtime error
Attempts:
2 left
💡 Hint

Think about what kv.get returns and how to access the stored value.

📝 Syntax
intermediate
2:00remaining
Which option correctly deletes a key from Deno KV?

You want to delete the key ["session", "abc"] from Deno KV. Which code snippet will do this correctly?

Aawait kv.deleteKey(["session", "abc"]);
Bawait kv.delete(["session", "abc"]);
Cawait kv.del(["session", "abc"]);
Dawait kv.remove(["session", "abc"]);
Attempts:
2 left
💡 Hint

Check the official Deno KV API method names.

❓ state_output
advanced
2:00remaining
What is the value of count after this transaction?

Given this code snippet using a Deno KV transaction:

const kv = await Deno.openKv();
await kv.set(["counter"], 0);

const tx = kv.atomic();
const current = await tx.get(["counter"]);
await tx.set(["counter"], (current.value ?? 0) + 1);
await tx.commit();

const result = await kv.get(["counter"]);
const count = result.value;

What is the value of count after running this code once?

Deno
const kv = await Deno.openKv();
await kv.set(["counter"], 0);

const tx = kv.atomic();
const current = await tx.get(["counter"]);
await tx.set(["counter"], (current.value ?? 0) + 1);
await tx.commit();

const result = await kv.get(["counter"]);
const count = result.value;
A1
Bundefined
C0
DThrows a runtime error
Attempts:
2 left
💡 Hint

Think about how the transaction increments the counter.

🔧 Debug
advanced
2:00remaining
Why does this Deno KV code throw an error?

Look at this code snippet:

const kv = await Deno.openKv();
await kv.set("user:1", { name: "Bob" });

It throws a runtime error. What is the cause?

Deno
const kv = await Deno.openKv();
await kv.set("user:1", { name: "Bob" });
AThe key must be an array of strings or numbers, not a single string
BThe value must be a string, not an object
CDeno KV requires keys to be numbers only
DThe set method requires a third argument for options
Attempts:
2 left
💡 Hint

Check the expected key format for Deno KV.

🧠 Conceptual
expert
2:00remaining
Which statement about Deno KV consistency is true?

Consider Deno KV's consistency guarantees. Which of these statements is correct?

ADeno KV provides strong consistency for all reads and writes globally
BDeno KV provides eventual consistency for reads but strong consistency for writes within a transaction
CDeno KV does not support transactions and consistency is not guaranteed
DDeno KV provides strong consistency only within atomic transactions, but reads outside may be eventually consistent
Attempts:
2 left
💡 Hint

Think about how atomic transactions affect consistency in distributed KV stores.

Practice

(1/5)
1. What is the main purpose of KV on Deno Deploy?
easy
A. To create user interfaces
B. To run heavy computations on the server
C. To store small pieces of data in the cloud
D. To manage network connections

Solution

  1. Step 1: Understand KV storage role

    KV on Deno Deploy is designed to store small data pieces like counters or preferences.
  2. Step 2: Compare options with KV purpose

    Only To store small pieces of data in the cloud matches storing small data in the cloud, others describe unrelated tasks.
  3. Final Answer:

    To store small pieces of data in the cloud -> Option C
  4. Quick Check:

    KV stores small data = A [OK]
Hint: KV is for small cloud data storage, not heavy tasks [OK]
Common Mistakes:
  • Confusing KV with computation services
  • Thinking KV manages UI or network
  • Assuming KV handles large files
2. Which of the following is the correct syntax to save a value '42' with key 'count' using KV in Deno Deploy?
easy
A. await kv.set('count', 42);
B. kv.set('count', 42);
C. await kv.get('count', 42);
D. kv.get('count', 42);

Solution

  1. Step 1: Identify correct method to save data

    Saving data uses kv.set with await to handle the async operation.
  2. Step 2: Check syntax correctness

    await kv.set('count', 42); uses await kv.set('count', 42); which is correct syntax. Options C and D use get which reads data, not saves.
  3. Final Answer:

    await kv.set('count', 42); -> Option A
  4. Quick Check:

    Save data = await kv.set() [OK]
Hint: Use await with kv.set to save data asynchronously [OK]
Common Mistakes:
  • Omitting await causing unresolved promises
  • Using kv.get instead of kv.set to save
  • Passing wrong number of arguments
3. What will be the output of this code snippet on Deno Deploy KV?
const value = await kv.get('visits');
console.log(value);
Assuming 'visits' key was never set before.
medium
A. undefined
B. null
C. Throws an error
D. 0

Solution

  1. Step 1: Understand kv.get behavior for missing keys

    If a key does not exist, kv.get returns null, not undefined or error.
  2. Step 2: Analyze console.log output

    Since 'visits' was never set, value is null, so console.log prints null.
  3. Final Answer:

    null -> Option B
  4. Quick Check:

    Missing key returns null = C [OK]
Hint: Missing KV keys return null, not undefined or error [OK]
Common Mistakes:
  • Expecting undefined instead of null
  • Assuming kv.get throws error for missing keys
  • Thinking default numeric 0 is returned
4. Identify the error in this Deno Deploy KV code snippet:
const result = kv.set('score', 100);
console.log('Score saved:', result);
medium
A. Missing await before kv.set causing unresolved promise
B. kv.set does not accept string keys
C. kv.set should be kv.save
D. console.log syntax is incorrect

Solution

  1. Step 1: Check async usage of kv.set

    kv.set is asynchronous and returns a promise, so it needs await to resolve.
  2. Step 2: Verify other parts of code

    Keys can be strings, kv.set is correct method, and console.log syntax is valid.
  3. Final Answer:

    Missing await before kv.set causing unresolved promise -> Option A
  4. Quick Check:

    Async kv.set needs await = D [OK]
Hint: Always await kv.set to avoid unresolved promises [OK]
Common Mistakes:
  • Forgetting await on async kv.set
  • Using wrong method name like kv.save
  • Misunderstanding console.log syntax
5. You want to implement a visitor counter using KV on Deno Deploy. Which approach correctly increments the count each time a visitor arrives?
hard
A. await kv.set('visits', (await kv.get('visits')) + 1);
B. kv.set('visits', 1);
C. const current = kv.get('visits') || 0; kv.set('visits', current + 1);
D. const current = await kv.get('visits') ?? 0; await kv.set('visits', current + 1);

Solution

  1. Step 1: Retrieve current count safely

    Use await kv.get('visits') and default to 0 if null using ?? operator.
  2. Step 2: Increment and save updated count

    Add 1 to current count and await kv.set to save it asynchronously.
  3. Step 3: Analyze options for correctness

    const current = await kv.get('visits') ?? 0; await kv.set('visits', current + 1); correctly handles async and null values. await kv.set('visits', (await kv.get('visits')) + 1); misses null check, C misses await, D resets count always.
  4. Final Answer:

    const current = await kv.get('visits') ?? 0; await kv.set('visits', current + 1); -> Option D
  5. Quick Check:

    Safe get + increment + await set = B [OK]
Hint: Use null coalescing and await both get and set [OK]
Common Mistakes:
  • Not awaiting async calls
  • Not handling null from kv.get
  • Resetting count instead of incrementing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard