javascriptbeginner
JavaScript Basics Quiz
Variables, types, operators, functions, and core JavaScript concepts.
7 questions
By EZ4Code Team
1. Which keyword declares a block-scoped variable that CANNOT be reassigned?
var
let
const
static
Explanation: `const` declares a block-scoped variable that cannot be reassigned. `let` is block-scoped but reassignable. `var` is function-scoped and reassignable. `static` is not a JavaScript variable keyword.
2. What does `typeof null` return in JavaScript?
console.log(typeof null);"null"
"object"
"undefined"
"number"
Explanation: This is a famous JavaScript quirk: `typeof null` returns `"object"`. It's a legacy bug from the original implementation that can't be fixed without breaking existing code. To check for null, use `value === null`.
3. What is the output?
console.log(0.1 + 0.2 === 0.3);true
false
Error
undefined
Explanation: Floating-point math in JavaScript (IEEE 754) gives `0.1 + 0.2 = 0.30000000000000004`, not exactly `0.3`. So the strict equality check returns `false`. Use `Math.abs(a - b) < Number.EPSILON` for float comparison.
4. Which method adds an element to the END of an array?
push()
pop()
shift()
unshift()
Explanation: `push()` adds to the end. `pop()` removes from the end. `shift()` removes from the beginning. `unshift()` adds to the beginning.
5. What does `"5" + 3` evaluate to?
console.log("5" + 3);8
"53"
53 (number)
NaN
Explanation: When you use `+` with a string, JavaScript coerces the other operand to a string and concatenates. So `"5" + 3` becomes `"53"` (a string). Note: `"5" - 3` would give `2` because `-` triggers numeric coercion.
6. Which operator checks both value AND type?
==
===
=
!=
Explanation: `===` is strict equality — it checks both value and type without coercion. `==` is loose equality and performs type coercion (e.g. `"5" == 5` is `true`). `=` is assignment, not comparison.
7. What does `console.log(typeof undefined)` print?
"undefined"
"null"
"object"
"string"
Explanation: `typeof undefined` returns the string `"undefined"`. This is the correct, expected behavior (unlike `typeof null` which returns `"object"` due to a legacy bug).
More javascript Quizzes
JavaScript ES6+ Quiz
intermediateArrow functions, destructuring, promises, modules, and modern JavaScript features.
JavaScript DOM Manipulation
intermediateDOM manipulation and event handling
JavaScript Asynchronous Programming
intermediatePromise, async/await, fetch
JavaScript Array Methods
intermediatemap, filter, reduce and other array higher-order methods
JavaScript Closures and Scope
advancedClosures, scope chain and hoisting