Bird
Raised Fist0
Denoframework~20 mins

Deno KV (built-in key-value store) - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deno KV Mastery
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 get operation?

Consider this code snippet using Deno KV:

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);

What will be logged to 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);
Anull
Bundefined
C{"name":"Alice","age":30}
D{"user":"123"}
Attempts:
2 left
💡 Hint

Remember that kv.get() returns an object with a value property containing the stored data.

❓ state_output
intermediate
2:00remaining
What is the value of 'count' after these Deno KV operations?

Given this code:

const kv = await Deno.openKv();
await kv.set(["counter"], 1);
await kv.set(["counter"], 2);
const { value: count } = await kv.get(["counter"]);
console.log(count);

What will be printed?

Deno
const kv = await Deno.openKv();
await kv.set(["counter"], 1);
await kv.set(["counter"], 2);
const { value: count } = await kv.get(["counter"]);
console.log(count);
A2
B1
Cundefined
Dnull
Attempts:
2 left
💡 Hint

Think about what happens when you set the same key twice.

🔧 Debug
advanced
2:00remaining
Which option will cause a runtime error when using Deno KV keys?

Deno KV keys must be arrays of strings or numbers. Which of these key usages will cause a runtime error?

Deno
const kv = await Deno.openKv();
await kv.set(KEY, "value");
AKEY = ["user", 123];
BKEY = "user:123";
CKEY = ["user", "123"];
DKEY = ["user", 123, "profile"];
Attempts:
2 left
💡 Hint

Remember that keys must be arrays, not strings.

🔧 Debug
advanced
2:00remaining
Why does this Deno KV code throw a TypeError?

Look at this code:

const kv = await Deno.openKv();
await kv.set("user", { name: "Bob" });
const result = await kv.get("user");
console.log(result.value);

Why does it throw a TypeError?

Deno
const kv = await Deno.openKv();
await kv.set("user", { name: "Bob" });
const result = await kv.get("user");
console.log(result.value);
ABecause keys must be arrays, not strings
BBecause the value must be a string, not an object
CBecause Deno KV does not support await
DBecause the key "user" is reserved
Attempts:
2 left
💡 Hint

Check the type of the key argument in set and get.

🧠 Conceptual
expert
2:00remaining
Which option correctly describes Deno KV transactions?

Which statement about Deno KV transactions is true?

ADeno KV does not support transactions; each operation is independent
BTransactions in Deno KV are synchronous and block the event loop until complete
CTransactions require manual locking of keys before operations
DTransactions allow multiple operations to be executed atomically and can be retried automatically on conflicts
Attempts:
2 left
💡 Hint

Think about atomicity and concurrency control in key-value stores.

Practice

(1/5)
1. What is the correct way to store a value in Deno KV?
easy
A. Use kv.set(["key"], value) to save data.
B. Use kv.save("key", value) to save data.
C. Use kv.put("key", value) to save data.
D. Use kv.store(["key"], value) to save data.

Solution

  1. Step 1: Understand Deno KV key format

    Deno KV uses arrays as keys, so keys must be passed as arrays like ["key"].
  2. Step 2: Identify the correct method to save data

    The method to save data is set, so kv.set(["key"], value) is correct.
  3. Final Answer:

    Use kv.set(["key"], value) to save data. -> Option A
  4. Quick Check:

    Key as array + set method = Use kv.set(["key"], value) to save data. [OK]
Hint: Remember: keys are arrays and method is set [OK]
Common Mistakes:
  • Using string keys instead of array keys
  • Using wrong method names like save or put
  • Passing key as a single string instead of array
2. Which of the following is the correct syntax to read a value from Deno KV?
easy
A. const result = kv.get(["key"]);
B. const result = await kv.get("key");
C. const result = await kv.get(["key"]);
D. const result = kv.get("key");

Solution

  1. Step 1: Recognize key format for get method

    Deno KV requires keys as arrays, so the key must be passed as ["key"].
  2. Step 2: Confirm asynchronous usage of get

    The get method is asynchronous, so it must be awaited.
  3. Final Answer:

    const result = await kv.get(["key"]); -> Option C
  4. Quick Check:

    Await + array key + get method = const result = await kv.get(["key"]); [OK]
Hint: Always await get and use array keys [OK]
Common Mistakes:
  • Not awaiting the get method
  • Passing key as string instead of array
  • Using synchronous call without await
3. What will be the output of this code snippet?
const kv = await Deno.openKv();
await kv.set(["user", "name"], "Alice");
const result = await kv.get(["user", "name"]);
console.log(result.value);
medium
A. undefined
B. "Alice"
C. null
D. Throws an error

Solution

  1. Step 1: Store value with key ["user", "name"]

    The code stores the string "Alice" under the key array ["user", "name"].
  2. Step 2: Retrieve the stored value using the same key

    The get method fetches the stored value, which is "Alice".
  3. Final Answer:

    "Alice" -> Option B
  4. Quick Check:

    Set then get with same key returns stored value [OK]
Hint: Set then get with same key returns stored value [OK]
Common Mistakes:
  • Expecting key as string instead of array
  • Not awaiting async calls
  • Confusing result object with direct value
4. Identify the error in this Deno KV usage:
const kv = await Deno.openKv();
await kv.set("session", "active");
const status = await kv.get(["session"]);
console.log(status.value);
medium
A. The key in set should be an array, not a string.
B. The get method should not be awaited.
C. The value "active" must be an object, not a string.
D. The console.log should print status directly, not status.value.

Solution

  1. Step 1: Check key format in set method

    The set method requires the key to be an array, but here it is a string "session".
  2. Step 2: Confirm correct key format for get method

    The get method uses the key as an array ["session"], which is correct.
  3. Final Answer:

    The key in set should be an array, not a string. -> Option A
  4. Quick Check:

    Key must be array in set and get [OK]
Hint: Keys must always be arrays in set and get [OK]
Common Mistakes:
  • Using string keys instead of array keys
  • Not awaiting async methods
  • Misunderstanding value access from get result
5. You want to store user preferences with keys like ["user", userId, "prefs"] and values as objects. Which code correctly updates preferences for userId 42 without overwriting other keys?
const kv = await Deno.openKv();
const userId = 42;
const newPrefs = { theme: "dark" };
// Which code below is correct?
hard
A. await kv.set([userId, "prefs"], newPrefs);
B. await kv.set(["user", "prefs"], newPrefs);
C. await kv.set(["user", userId], newPrefs);
D. await kv.set(["user", userId, "prefs"], newPrefs);

Solution

  1. Step 1: Understand key structure for user preferences

    The key must include "user", the userId, and "prefs" to uniquely identify preferences per user.
  2. Step 2: Check which option uses the full key correctly

    await kv.set(["user", userId, "prefs"], newPrefs); uses ["user", userId, "prefs"] which matches the required key structure.
  3. Final Answer:

    await kv.set(["user", userId, "prefs"], newPrefs); -> Option D
  4. Quick Check:

    Full key array with userId keeps keys unique [OK]
Hint: Include userId in key array to avoid overwriting [OK]
Common Mistakes:
  • Omitting userId from key causing overwrites
  • Using incomplete key arrays
  • Confusing order of key elements
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