JavaScript Operators Quiz 1. What is the result of 3 + '2' in JavaScript? A. 5 B. 32 C. NaN D. Undefined String concatenation occurs because one operand is a string. 2. What is the result of '5' - 2? A. '3' B. 5 C. 3 D. NaN The minus operator converts strings to numbers (5 - 2 = 3). 3. Which operator checks both value and type? A. == B. equals() C. === D. != === performs strict comparison (value + type). 4. What is the result of 0 == false? A. true B. false C. 0 D. Error Loose equality converts both sides before comparison. 5. What is the result of 0 === false? A. true B. false C. 0 D. Error Strict equality does not perform type conversion. 6. What does typeof return for an array? A. array B. object C. list D. collection Arrays are objects in JavaScript; typeof returns 'object'. 7. What is 2 ** 3? A. 6 B. 4 C. 8 D. 9 Exponentiation operator computes 2 * 2 * 2 = 8. 8. What is '10' / '2'? A. 5 B. '5' C. NaN D. undefined Division converts strings to numbers. 9. Which operator is optional chaining? A. ?? B. ?. C. :: D. --? Optional chaining avoids errors when accessing null/undefined values. 10. What is typeof undefined? A. 'null' B. 'object' C. 'undefined' D. 'void' typeof undefined returns the string 'undefined'. 11. What does the nullish coalescing operator (??) return? A. First truthy value B. First defined value C. Always left operand D. Always right operand ?? returns right side only if left is null or undefined. 12. What is the result of true + true? A. 1 B. 2 C. true D. NaN true converts to 1; 1 + 1 = 2. 13. What is typeof NaN? A. number B. NaN C. undefined D. object NaN is classified as a number in JavaScript. 14. What is the result of '4' * '2'? A. 42 B. '8' C. NaN D. 8 The * operator converts both strings to numbers. 15. What does !!value convert to? A. integer B. boolean C. string D. undefined !! forces conversion to a boolean value. 16. Which operator has the highest precedence? A. == B. && C. * D. || Multiplication has higher precedence than comparison and logical operators. 17. What is [] == '' ? A. true B. false C. Error D. undefined [] converts to an empty string ('') when coerced. 18. What is the result of [] === []? A. true B. false C. Error D. undefined Different array instances are never strictly equal. 19. What does typeof return for functions? A. 'object' B. 'function' C. 'callable' D. 'method' typeof returns 'function' for all functions. 20. Which operator assigns only if the left side is null or undefined? A. = B. ??= C. &&= D. ||= ??= assigns only when the left side is nullish. 21. What is +true? A. true B. 1 C. NaN D. undefined Unary + converts true to number 1. 22. What is +'7'? A. 7 B. '7' C. NaN D. undefined Unary + converts numeric strings into numbers. 23. What is 1 < 2 < 0? A. true B. false C. 1 D. undefined 1 < 2 is true u2192 true becomes 1 u2192 1 < 0 is false. 24. What is typeof null? A. null B. object C. undefined D. primitive typeof null returns 'object' due to legacy behavior. 25. What is [] + {}? A. '[object Object]' B. {} C. [] D. NaN [] converts to '' and {} converts to '[object Object]' when concatenated. Submit
JavaScript Variables Quiz 1. What keyword lets you create a changeable variable? A) let B) const C) var D) static Correct answer: A (let). let makes a variable you can change. 2. Which keyword creates a variable that cannot change? A) let B) const C) var D) none Correct answer: B (const). const cannot be changed. 3. Which keyword is used in old JavaScript? A) var B) let C) const D) old Correct answer: A (var). var is the old keyword. 4. What value does var have before setting it? A) 0 B) undefined C) null D) empty Correct answer: B (undefined). var starts as undefined. 5. What happens if you use let before declaring it? A) It works B) It becomes zero C) It gives an error D) It resets Correct answer: C (error). let gives ReferenceError. 6. Which keyword stays inside a block? A) var B) let C) global D) none Correct answer: B (let). let is block scoped. 7. Which keyword ignores block scope? A) var B) let C) const D) none Correct answer: A (var). var ignores blocks. 8. Which keyword is best for fixed values? A) let B) const C) var D) none Correct answer: B (const). const is for fixed values. 9. Which variable can change? A) const B) let C) static D) none Correct answer: B (let). let can change. 10. Which variable must have a value when created? A) var B) let C) const D) none Correct answer: C (const). const requires a value. 11. Which keyword should be avoided? A) const B) let C) var D) none Correct answer: C (var). var is unsafe. 12. What happens if you redeclare let? A) It works B) It errors C) It resets D) It ignores Correct answer: B. let cannot be redeclared. 13. What happens if you assign without var/let/const? A) It stops B) It becomes global C) It warns D) It resets Correct answer: B. It creates a global variable. 14. Which variable shows undefined before setting? A) var B) let C) const D) none Correct answer: A (var). var logs undefined. 15. Which variables throw ReferenceError before setting? A) var B) let C) const D) let and const Correct answer: D. let and const do this. 16. Which becomes part of window object? A) let B) var C) const D) none Correct answer: B (var). var attaches to window. 17. Which is best for loop counters? A) var B) let C) const D) none Correct answer: B (let). let is safer. 18. Which keyword allows shadowing? A) var B) let C) const D) none Correct answer: B (let). let allows shadowing. 19. Which keyword was added in ES6? A) var B) let C) const D) none Correct answer: B (let). let was added in ES6. 20. Which variable is safest for beginners? A) var B) let C) const D) none Correct answer: C (const). const avoids mistakes. Submit