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 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 understanding of key JavaScript topics with these…
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 QuizChallenge your JavaScript fundamentals with 15 essential interview questions covering core concepts like variables, functions, data types, and scope. Gain confidence in JavaScript basics and key features common in technical interviews.
This quiz contains 16 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 description best defines JavaScript as a programming language?
Correct answer: A high-level, interpreted scripting language mainly used for web development.
Explanation: JavaScript is a high-level, interpreted language widely used for creating interactive web pages and applications. It runs primarily in browsers but is also used on servers. The other options describe different types of languages or tools that are not accurate descriptions of JavaScript. For example, the second option refers to SQL, the third to languages like C, and the fourth to spreadsheet formulas.
What is the main difference between let and var when declaring variables in JavaScript?
Correct answer: let is block-scoped while var is function-scoped.
Explanation: The primary difference is that let is block-scoped and var is function-scoped, meaning let variables exist only in the nearest enclosing block, while var variables are available throughout their containing function. The second option is incorrect; var can be redeclared but let cannot in the same scope. The third option is false, as var is older. The fourth option reverses the actual hoisting behavior.
Which statement about const declarations in JavaScript is correct?
Correct answer: Variables declared with const cannot be reassigned.
Explanation: The correct answer is that variables declared with const cannot be reassigned to a new value, ensuring their reference remains constant. The second option is false because const does not allow reassignment. The third is incorrect, as const is block-scoped. The fourth option is wrong because const variables must be initialized at declaration and are not always undefined.
Which of the following is NOT a primitive data type in JavaScript?
Correct answer: Object
Explanation: Objects are not primitive data types in JavaScript; they are complex structures. The other options—String, Boolean, and Number—are all valid primitive data types. This distinction is key in understanding how data is stored and manipulated in JavaScript.
How do you correctly declare a named function in JavaScript?
Correct answer: function greet() { return 'Hello'; }
Explanation: The standard way to declare a named function in JavaScript uses the function keyword followed by the function name, as in the correct answer. The other options use incorrect syntax or keywords not found in JavaScript. For instance, 'define' and 'func' are not valid, and using brackets as in the last option is also invalid.
Which syntax creates an arrow function that returns the sum of two numbers?
Correct answer: (a, b) => a + b
Explanation: The correct syntax for an arrow function in JavaScript is (a, b) => a + b. The next two options use invalid function syntax, either missing commas or using undefined keywords. The last option uses incorrect symbols and simplistic English instead of code, which is not valid in JavaScript.
What does the '===' operator check for in JavaScript?
Correct answer: Both strict value and type equality.
Explanation: The strict equality operator '===' checks for equality of both value and data type. The second option refers to '==' which checks only value. The third is incorrect because '===' checks both, not just type. The fourth refers to operators like '!='.
What is the result of typeof undefined in JavaScript?
Correct answer: 'undefined'
Explanation: When using typeof undefined, the result is the string 'undefined'. 'null' would return 'object' instead. The options 'object' and 'string' are incorrect because only undefined produces the provided result when passed to typeof.
Which syntax uses a template literal to include the variable name in the output?
Correct answer: `Hello, ${name}!`
Explanation: Template literals in JavaScript use backticks and the ${} syntax to interpolate variables, as shown in the correct answer. The single and double quote options use incorrect variable notation, and the last option uses string concatenation, not a template literal.
Which example correctly sets a default value for a function parameter?
Correct answer: function greet(name = 'Guest') { return name; }
Explanation: Setting a default value is done by assigning a value during parameter declaration, as in the correct answer. The second option uses a colon, which is not valid syntax. The third option assigns a value inside the function, but this can overwrite any passed value. The fourth option uses an invalid bracket syntax.
Which of these is a falsy value in JavaScript?
What method adds a new element to the end of an array in JavaScript?
Correct answer: push()
Explanation: The push() method adds an element to the end of an array. The unshift() method adds to the beginning. The pop() method removes from the end, and shift() removes from the beginning. Only push() performs the described action.
Which JavaScript loop is best used to iterate through all keys in an object?
Correct answer: for...in
Explanation: The for...in loop iterates over the enumerable property keys of an object. The for...of loop is used for iterable objects like arrays, which is different. The standard while loop does not directly iterate through keys. 'do...in' is not a valid JavaScript loop syntax.
What does a closure in JavaScript allow you to do?
Correct answer: Access variables from an outer function even after it finishes execution.
Explanation: A closure enables inner functions to access variables from an outer function's scope even after the outer function has returned. The second option describes no real mechanism. Converting strings to integers is unrelated. The last option partially reflects let scope, not closures.
Which method attaches an event handler to a DOM element in JavaScript?
Correct answer: addEventListener()
Explanation: addEventListener() is the correct JavaScript method to attach an event handler to a DOM element. The other options are either outdated or not part of standard JavaScript API. For example, attachEventHandler() and listenEvent() do not exist.
What is variable hoisting in JavaScript?
Correct answer: The process where variable declarations are moved to the top of their scope.
Explanation: Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their containing scope during compilation. It has nothing to do with string conversion, variable sorting, or automatic clearance at the end of execution. Only the first option explains the correct behavior.