JavaScript Variables & Data Types Quiz

JavaScript
0 Passed
0% acceptance

A focused JavaScript quiz dedicated to variables, scope, primitive values, reference types, and type conversion. Use this set to check how well you understand declarations, assignments, comparison rules, and everyday runtime behaviour.

50 Questions
~100 minutes
1

Question 1

Which declaration keyword creates a variable whose binding cannot be reassigned?

A
var
B
let
C
const
D
static
2

Question 2

What is logged in the console?

javascript
console.log(typeof null)
A
"null"
B
"object"
C
"undefined"
D
"boolean"
3

Question 3

What will this code output?

javascript
let count
console.log(count === undefined)
A
true
B
false
C
Throws ReferenceError
D
null
4

Question 4

Which statement about primitive values is correct?

A
They are stored by reference
B
They are immutable
C
They can have properties assigned dynamically
D
They are all objects internally
5

Question 5

What does this log?

javascript
const arr = [1, 2]
const copy = arr
copy.push(3)
console.log(arr.length)
A
2
B
3
C
undefined
D
Throws TypeError
6

Question 6

Which value is NOT falsy in JavaScript?

A
0
B
""
C
NaN
D
"false"
7

Question 7

What will be printed?

javascript
const a = { value: 1 }
const b = { value: 1 }
console.log(a === b)
A
true
B
false
C
Throws ReferenceError
D
undefined
8

Question 8

Which method converts the string "42" to the number 42 using unary syntax?

A
Number("42")
B
parseInt("42")
C
+ "42"
D
"42".toNumber()
9

Question 9

How many primitive data types exist in JavaScript (ES2020)?

A
Six
B
Seven
C
Eight
D
Nine
10

Question 10

What does this log?

javascript
let x = 5
x += "5"
console.log(x)
A
10
B
"55"
C
"10"
D
NaN
11

Question 11

What is hoisting behaviour for variables declared with var?

A
The declaration is hoisted with an initial value of undefined
B
The declaration and assignment are fully hoisted
C
Neither declaration nor assignment is hoisted
D
Only the assignment is hoisted
12

Question 12

What will be logged?

javascript
console.log(typeof Symbol("id"))
A
"symbol"
B
"object"
C
"string"
D
"function"
13

Question 13

Which statement correctly describes BigInt?

A
It stores floating-point numbers with high precision
B
It represents whole numbers larger than Number can safely store
C
It is only available in strict mode
D
It can be mixed with regular numbers without issues
14

Question 14

What is output?

javascript
const score = "7"
console.log(score - 2)
A
"72"
B
5
C
NaN
D
"5"
15

Question 15

How do you check if a value is NaN using the most robust approach?

A
value === NaN
B
Number.isNaN(value)
C
value == NaN
D
typeof value === "NaN"
16

Question 16

What is logged?

javascript
let name = "Ada"
function show() {
  let name = "Grace"
  console.log(name)
}
show()
console.log(name)
A
"Ada" then "Grace"
B
"Grace" then "Ada"
C
"Grace" then "Grace"
D
"Ada" then "Ada"
17

Question 17

Which comparison returns true?

A
Object.is(NaN, NaN)
B
NaN === NaN
C
NaN == NaN
D
Number.NaN === NaN
18

Question 18

What will `typeof []` return?

A
"array"
B
"object"
C
"function"
D
"list"
19

Question 19

Which statement best describes `let` declarations?

A
They are function-scoped
B
They can be redeclared within the same scope
C
They are block-scoped and cannot be redeclared in the same block
D
They are globally hoisted
20

Question 20

What is logged?

javascript
const greeting = `Hello, ${"JS".toLowerCase()}!`
console.log(greeting)
A
"Hello, js!"
B
"Hello, JS!"
C
"Hello, ${js}!"
D
"Hello, undefined!"
21

Question 21

Which operation converts a number to a string?

A
String(10)
B
10..toFixed(0)
C
`${10}`
D
All of the above
22

Question 22

What does this output?

javascript
const value = Boolean("0")
console.log(value)
A
true
B
false
C
0
D
Throws TypeError
23

Question 23

Which operator checks reference equality for objects?

A
==
B
===
C
=
D
=== and Object.is
24

Question 24

What happens when you access an undeclared variable?

A
Returns undefined
B
Returns null
C
Throws ReferenceError
D
Creates a global variable automatically
25

Question 25

What is the result?

javascript
const total = Number("5") + Number(true)
console.log(total)
A
6
B
5
C
NaN
D
"5true"
26

Question 26

Which method converts a value to a string in base 2?

A
(42).toString(2)
B
String(42, 2)
C
parseInt(42, 2)
D
Number.toString(42, 2)
27

Question 27

What does this log?

javascript
let value = 0
console.log(value ?? 10)
A
0
B
10
C
null
D
undefined
28

Question 28

What is printed?

javascript
const scores = Object.freeze([1, 2, 3])
scores[0] = 99
console.log(scores[0])
A
99
B
1
C
undefined
D
Throws TypeError
29

Question 29

Which expression returns true?

A
Array.isArray({ length: 0 })
B
Array.isArray([])
C
typeof [] === "array"
D
[] instanceof Object === false
30

Question 30

How many arguments does the parseInt function accept?

A
One required and one optional radix
B
Exactly one
C
Two required parameters
D
Three parameters including precision
31

Question 31

What does this log?

javascript
console.log(typeof (() => {}))
A
"object"
B
"function"
C
"arrow"
D
"callable"
32

Question 32

Which statement is true about const declarations?

A
They must be initialised at declaration time
B
They can be declared without assigning a value
C
They can be redeclared in the same scope
D
They automatically deep-freeze objects
33

Question 33

What is the result?

javascript
const message = "5" + 3
console.log(typeof message)
A
"string"
B
"number"
C
"object"
D
"undefined"
34

Question 34

What will `typeof NaN` return?

A
"NaN"
B
"number"
C
"undefined"
D
"object"
35

Question 35

Which expression produces NaN?

A
Number("123")
B
parseFloat("45.6")
C
+"9"
D
Number("12px")
36

Question 36

What does this log?

javascript
let value
console.log(typeof value)
A
"undefined"
B
"null"
C
"object"
D
"string"
37

Question 37

Which statement about typeof is true?

A
typeof null returns "null"
B
typeof function(){} returns "function"
C
typeof [] returns "array"
D
typeof NaN returns "NaN"
38

Question 38

What is printed?

javascript
let count = 0
if (!count) {
  count = 5
}
console.log(count)
A
0
B
5
C
null
D
undefined
39

Question 39

Which option correctly uses optional chaining?

A
user.address.street?
B
user?.address?.street
C
user!address!street
D
user.address??street
40

Question 40

What will this output?

javascript
const result = 1 / 0
console.log(result)
A
0
B
Infinity
C
NaN
D
Throws Error
41

Question 41

Which keyword is block scoped and subject to the temporal dead zone?

A
var
B
let
C
function
D
with
42

Question 42

What is the value of Boolean(undefined)?

A
true
B
false
C
undefined
D
Throws TypeError
43

Question 43

Which loose equality comparison evaluates to true?

A
0 == false
B
0 == "0"
C
"" == false
D
All of the above
44

Question 44

What is logged?

javascript
const value = +"hello"
console.log(value)
A
"hello"
B
NaN
C
undefined
D
0
45

Question 45

Which expression returns a symbol value?

A
Symbol("id")
B
new Symbol("id")
C
Symbol.concat("id")
D
symbol("id")
46

Question 46

What will this log?

javascript
const nums = Object.seal([1, 2, 3])
nums.push(4)
console.log(nums.length)
A
3
B
4
C
Throws TypeError
D
undefined
47

Question 47

Which statement is true about object references?

A
Assigning an object with = creates a deep copy
B
Mutating an object via one reference affects all references to it
C
Objects are compared structurally with ===
D
Objects cannot be passed to functions by reference
48

Question 48

What is the output?

javascript
const big = 10n
const num = 5
console.log(big + BigInt(num))
A
15n
B
15
C
Throws TypeError
D
NaN
49

Question 49

Which statement about JSON.stringify is correct?

A
It includes functions in the output by default
B
It omits properties whose values are undefined
C
It throws on plain objects
D
It automatically resolves circular references
50

Question 50

What will this log?

javascript
const settings = { theme: "dark" }
const copy = { ...settings }
copy.theme = "light"
console.log(settings.theme)
A
"dark"
B
"light"
C
undefined
D
Throws Error

QUIZZES IN JavaScript