Explore key concepts and features of asynchronous programming in…
Start QuizExplore underrated JavaScript libraries that offer powerful solutions for…
Start QuizExplore how pnpm 10 enhances package installation security and…
Start QuizExplore how JavaScript classes relate to prototypes, constructor functions,…
Start QuizDiscover the proven patterns and practical habits that distinguish…
Start QuizAssess your understanding of JavaScript modules, including import/export syntax,…
Start QuizChallenge your understanding of JavaScript function definitions, syntax, and…
Start QuizSharpen your understanding of JavaScript objects with these easy…
Start QuizExplore the basics of JavaScript loops with these straightforward…
Start QuizExplore easy questions covering fundamental JavaScript concepts, suitable for…
Start QuizExplore the basics of the JavaScript Event Loop, including…
Start QuizChallenge your JavaScript fundamentals with 15 essential interview questions…
Start QuizExplore essential concepts for handling dependencies across multi-package JavaScript…
Start QuizChallenge your understanding of fundamental JavaScript concepts with these…
Start QuizExplore the history and evolution of JavaScript, from its…
Start QuizEnhance your understanding of JavaScript with this beginner-friendly quiz…
Start QuizTest your understanding of common internet troubleshooting scenarios and…
Start QuizTest your knowledge of ES6 (ECMAScript 2015) features with…
Start QuizTest your knowledge with these commonly asked JavaScript interview…
Start QuizTest your knowledge of Observables in JavaScript, including their…
Start QuizTest your knowledge of essential JavaScript developer tips and…
Start QuizTest your knowledge of JavaScript ES6 features with this…
Start QuizTest your understanding of core JavaScript concepts relevant to…
Start QuizTest your understanding of Node.js fundamentals with this quiz…
Start QuizTest your understanding of key JavaScript topics with these beginner-friendly questions. This quiz covers core JavaScript interview concepts such as variable scope, hoisting, data types, and basic syntax to help you prepare effectively.
This quiz contains 10 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.
Which keyword in JavaScript declares a variable that is block-scoped and cannot be reassigned after its initial assignment?
Correct answer: const
Explanation: The correct answer is 'const' because it creates a block-scoped variable that cannot be reassigned after being created. 'let' is also block-scoped but allows reassignment. 'var' is function-scoped and not block-scoped, while 'cost' is a typo and not a valid JavaScript keyword.
What happens if you redeclare a variable using var within the same function scope?
Correct answer: The variable is overwritten
Explanation: 'var' allows variable re-declaration within the same scope, so the previously stored value is overwritten with the new one. It does not throw an error like 'let' and 'const' would. Redeclaring with var does not create a new scope, and the statement is not ignored.
Which of the following JavaScript declarations is hoisted to the top of its scope?
Correct answer: var
Explanation: 'var' declarations are hoisted to the top of their functional or global scope in JavaScript. 'let' and 'const' are not hoisted in a usable way; accessing them before declaration results in a ReferenceError. The 'import' statement behaves differently and is not hoisted like 'var'.
Which type of function can be called before its declaration due to hoisting?
Correct answer: Function declaration
Explanation: Function declarations are hoisted, so they can be called before their actual declaration in the code. Arrow functions and functions assigned to let or const are not hoisted in the same way. An anonymous function is simply a function without a name and may also be assigned to a variable, but unless it's declared via a function declaration, it won't be hoisted.
In the following code, what will be logged? let a = 5; if (true) { let a = 10; } console.log(a);
Correct answer: 5
Explanation: The correct answer is 5 because the 'let' inside the block creates a new variable scoped only to that block. The 'a' outside remains unchanged. 10 would have been correct if the inner 'a' overwrote the outer one, which it does not. 'undefined' and 'ReferenceError' are incorrect since the variable 'a' is properly declared and initialized in the outer scope.
Which of the following is NOT a primitive data type in JavaScript?
Correct answer: Object
Explanation: 'Object' is not a primitive data type in JavaScript; it is a complex type that can store collections of data. 'Boolean', 'String', and 'Number' are all considered primitive types. The distractors are commonly confused, but only 'Object' fails the primitive test.
How do you correctly write a function declaration in JavaScript?
Correct answer: function myFunc() {}
Explanation: The standard syntax for declaring a function in JavaScript is 'function myFunc() {}'. Option two is an arrow function expression, not a function declaration. Option three incorrectly uses TypeScript-style syntax, and option four uses an invalid keyword 'fun'.
Which operator is used to join two strings together in JavaScript?
Correct answer: +
Explanation: The '+' operator is used to concatenate strings in JavaScript. The period ('.') is not used for this purpose, nor are '-' or '*'. Using these other operators would produce errors or unintended results.
Which value is considered 'falsy' in JavaScript?
Which operator checks both value and type for equality in JavaScript?
Correct answer: ===
Explanation: The strict equality operator '===' checks both the value and the type of its operands. '==' checks value with type coercion, leading to potentially unexpected results. '!=' and '=!=' are not the strict equality operator; the latter is not a valid operator in JavaScript.