0
0
Javascriptprogramming~20 mins

Primitive data types in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 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?