Bird
Raised Fist0
Javascriptprogramming~20 mins

Primitive data types in Javascript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Primitive Data Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of typeof with different primitives
What is the output of the following code snippet?
Javascript
console.log(typeof null);
console.log(typeof undefined);
console.log(typeof 42);
console.log(typeof 'hello');
A
"object"
"undefined"
"number"
"string"
B
"null"
"undefined"
"number"
"string"
C
"object"
"null"
"number"
"string"
D
"undefined"
"undefined"
"number"
"string"
Attempts:
2 left
💡 Hint
Remember that typeof null is a known JavaScript quirk.
❓ Predict Output
intermediate
2:00remaining
Boolean conversion of different values
What is the output of this code?
Javascript
console.log(Boolean(0));
console.log(Boolean(''));
console.log(Boolean('false'));
console.log(Boolean(null));
A
false
false
false
false
B
true
false
true
false
C
false
true
true
false
D
false
false
true
false
Attempts:
2 left
💡 Hint
Check which values are considered falsy in JavaScript.
🧠 Conceptual
advanced
2:00remaining
Understanding Symbol uniqueness
Which statement about JavaScript Symbols is true?
ASymbols can be used as unique object property keys.
BSymbols are primitive but can be converted to strings automatically.
CTwo Symbols created with Symbol() are always equal.
DSymbols are mutable primitive values.
Attempts:
2 left
💡 Hint
Think about what makes Symbols special compared to strings.
❓ Predict Output
advanced
2:00remaining
Output of typeof with BigInt and other primitives
What is the output of this code?
Javascript
console.log(typeof 9007199254740991n);
console.log(typeof true);
console.log(typeof '123');
console.log(typeof undefined);
A
"number"
"boolean"
"string"
"undefined"
B
"bigint"
"boolean"
"string"
"undefined"
C
"bigint"
"boolean"
"number"
"undefined"
D
"bigint"
"boolean"
"string"
"null"
Attempts:
2 left
💡 Hint
BigInt is a newer primitive type in JavaScript.
🔧 Debug
expert
2:00remaining
Identify the error in primitive assignment
What error will this code produce?
Javascript
const str = 'hello';
str[0] = 'H';
console.log(str);
ATypeError: Cannot assign to read only property '0' of string
BSyntaxError: Invalid assignment
Chello
Dundefined
Attempts:
2 left
💡 Hint
Strings are immutable in JavaScript. What happens when you try to change a character?

Practice

(1/5)
1. Which of the following is NOT a primitive data type in JavaScript?
easy
A. object
B. boolean
C. string
D. number

Solution

  1. Step 1: Recall JavaScript primitive types

    JavaScript primitive types include string, number, boolean, undefined, null, symbol, and bigint.
  2. Step 2: Identify non-primitive types

    Object is not a primitive type; it is a complex data type used to store collections.
  3. Final Answer:

    object -> Option A
  4. Quick Check:

    Primitive types exclude objects [OK]
Hint: Remember: objects are NOT primitives, others are [OK]
Common Mistakes:
  • Confusing object with primitive types
  • Thinking null is an object
  • Mixing symbol with object
2. Which of the following is the correct way to declare a variable with a string primitive in JavaScript?
easy
A. let name = John;
B. let name = 'John';
C. let name = "John;
D. let name = `John;

Solution

  1. Step 1: Check string declaration syntax

    Strings must be enclosed in matching quotes: single ('') or double ("") or backticks (``).
  2. Step 2: Validate each option

    let name = 'John'; uses single quotes correctly. let name = John; lacks quotes. Options C and D have unclosed quotes.
  3. Final Answer:

    let name = 'John'; -> Option B
  4. Quick Check:

    Strings need matching quotes [OK]
Hint: Strings always need matching quotes around text [OK]
Common Mistakes:
  • Missing quotes around string
  • Using mismatched quotes
  • Forgetting semicolon (optional but good)
3. What will be the output of the following code?
console.log(typeof 123);
console.log(typeof 'hello');
console.log(typeof true);
medium
A. "number", "string", "boolean"
B. "Number", "String", "Boolean"
C. "num", "str", "bool"
D. "integer", "text", "bool"

Solution

  1. Step 1: Understand typeof operator

    typeof returns the type of a value as a lowercase string like "number", "string", or "boolean".
  2. Step 2: Check each console.log output

    typeof 123 is "number", typeof 'hello' is "string", typeof true is "boolean".
  3. Final Answer:

    "number", "string", "boolean" -> Option A
  4. Quick Check:

    typeof returns lowercase type names [OK]
Hint: typeof returns lowercase type names as strings [OK]
Common Mistakes:
  • Capitalizing type names
  • Using short forms like 'num'
  • Confusing typeof output with values
4. Find the error in this code snippet:
let value = null;
console.log(typeof value);
medium
A. null is not a valid value
B. typeof null returns 'null'
C. typeof null returns 'object' which is confusing
D. No error, code works fine

Solution

  1. Step 1: Understand typeof null behavior

    typeof null returns "object" due to a historical JavaScript bug.
  2. Step 2: Identify confusion

    This is confusing because null is a primitive but typeof shows "object".
  3. Final Answer:

    typeof null returns 'object' which is confusing -> Option C
  4. Quick Check:

    typeof null is 'object' (quirk) [OK]
Hint: Remember typeof null is 'object' due to JavaScript quirk [OK]
Common Mistakes:
  • Expecting 'null' from typeof
  • Thinking null is an object
  • Assuming code throws error
5. You want to store a very large integer number beyond the safe integer limit in JavaScript. Which primitive type should you use?
hard
A. number
B. symbol
C. string
D. bigint

Solution

  1. Step 1: Understand number limits in JavaScript

    The number type can safely represent integers only up to 2^53 - 1.
  2. Step 2: Identify type for large integers

    bigint is designed to store integers larger than the safe limit without losing precision.
  3. Final Answer:

    bigint -> Option D
  4. Quick Check:

    Use bigint for very large integers [OK]
Hint: Use bigint for integers larger than safe number limit [OK]
Common Mistakes:
  • Using number for very large integers
  • Using string instead of bigint
  • Confusing symbol with number types
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