JavaScript Basic Questions

Test your JavaScript fundamentals with 20 self-contained practice questions covering variables, data types, equality, truthy and falsy values, conditions, loops, functions, scope, exception handling and NaN. No external question engine is required.

How to use this practice set: answer all questions first, then select Check Answers. Your score and a short explanation for every question will appear. You can change answers and check again, or reset the quiz and start over.
1. Which keyword declares a block-scoped variable that can be reassigned?
let is block-scoped and can be reassigned. const is also block-scoped, but the binding cannot be reassigned.
2. What happens if you try to reassign a variable declared with const?
Reassigning a const binding throws a TypeError. The contents of an object stored in a const can still be mutated unless the object itself is frozen.
3. Which statement about var is correct?
var is function-scoped rather than block-scoped. This is one reason modern code usually prefers let and const.
4. Which operator checks both value and type without coercion?
=== performs strict equality. It does not coerce the operands to another type before comparing them.
5. What does typeof null return?
typeof null returns "object". This is a long-standing historical quirk in JavaScript.
6. Which of these values is truthy?
Any non-empty string is truthy, even the string "false". The other three choices are falsy.
7. What is the result of "5" + 2?
With +, if one operand is a string, JavaScript performs string concatenation, so the result is "52".
8. What is the result of "5" - 2?
The - operator converts the numeric-looking string to a number, so 5 - 2 gives 3.
9. What does Boolean("false") return?
The string is non-empty, so it is truthy. Boolean("false") therefore returns true.
10. Which branch runs in if (0) { ... } else { ... }?
0 is falsy, so the else branch runs.
11. How many times does for (let i = 0; i < 3; i++) run its body?
The loop runs for i values 0, 1, and 2, so the body executes three times.
12. When does a while loop test its condition?
while checks its condition before each iteration. If the condition is false initially, the body does not run at all.
13. What does return do inside a function?
return ends the current function execution and can provide a value to the caller.
14. What does a JavaScript function return if it reaches the end without a return statement?
A function with no explicit returned value evaluates to undefined.
15. What is the main purpose of a function parameter?
Parameters are local names that receive argument values passed when the function is called.
16. What happens to a let variable declared inside an if block when code outside the block tries to use it?
let is block-scoped, so a variable declared inside { } is not available outside that block.
17. What happens if code reads a let variable before its declaration is reached?
A let binding exists in the temporal dead zone before its declaration is evaluated, so accessing it there throws a ReferenceError.
18. What is try...catch used for?
Code that may throw an exception goes in try; matching error handling goes in catch.
19. Which check correctly identifies the numeric NaN value?
Number.isNaN(value) is the reliable direct check for the numeric NaN value. NaN is not equal to itself.
20. What is the result of NaN === NaN?
NaN is the unusual JavaScript numeric value that is not equal to itself, so NaN === NaN is false.
Score: not checked yet.

What to review next Top ↑

If a question was difficult, use the related tutorial links below, review the example, and then retry the quiz. The goal is to understand why an answer is correct rather than memorize the score.




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer