---
title: "JavaScript: Language Fundamentals & Modern Features"
description: "Test your knowledge of JavaScript fundamentals with this comprehensive quiz covering variables, data types, functions, promises, DOM manipulation, ES6 features, closures, and modern JavaScript programming best practices."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/javascript-fundamentals-quiz
---

# JavaScript: Language Fundamentals & Modern Features

Welcome to the JavaScript Basics Quiz! This quiz is designed to test your understanding of fundamental JavaScript concepts, syntax, and modern programming best practices. Each question is multiple-choice, and you'll find hints to help you along the way. Good luck!

## Questions

### 1. Which keyword is used to declare a block-scoped variable that can be reassigned?

- `var`
  - The "var" keyword is function-scoped rather than block-scoped and is subject to hoisting.
- **`let`** ✅
  - The "let" keyword provides block-scoping and permits the variable to be reassigned later.
- `const`
  - While block-scoped, "const" creates a constant reference that prevents value reassignment.
- `set`
  - The "set" keyword is used to define property setters within objects, not to declare variables.

**Hint:** Introduced in ES6 to replace "var".

### 2. What is the result of "5" + 2 in JavaScript?

- `7`
  - This result would require both operands to be numeric types without string coercion.
- **`"52"`** ✅
  - JavaScript coerces the number into a string and concatenates it with the existing string.
- `NaN`
  - NaN occurs when a mathematical operation fails, but addition involving a string is valid.
- `undefined`
  - An expression involving a valid string and number will resolve to a value rather than undefined.

**Hint:** JavaScript prioritizes string concatenation with the + operator.

### 3. How do you create a function using the arrow syntax?

- `function my_func => {}`
  - Arrow functions do not use the "function" keyword as part of their syntax.
- **`const my_func = () => {}`** ✅
  - This syntax defines an anonymous function and assigns it to a constant variable name.
- `let my_func = func() {}`
  - The "func" keyword is not used for function declaration in standard JavaScript.
- `my_func() -> { return }`
  - This syntax is used in languages like Rust or Swift but is invalid for JavaScript arrows.

**Hint:** Uses the "fat arrow" symbol =>.

### 4. What does "===" check that "==" does not?

- The scope of the variables
  - Scope is determined by declaration keywords, not by comparison operators.
- **Both the value and the type** ✅
  - Strict equality (===) ensures no type coercion occurs during the comparison process.
- Memory address consistency
  - While objects are compared by reference, strict equality for primitives checks value and type.
- Function execution status
  - Operators compare data states rather than the execution context of surrounding functions.

**Hint:** Think about data types.

### 5. Which method is used to write text directly into the browser console?

- `print.log()`
  - The global print() function is used to trigger the browser printer dialog.
- **`console.log()`** ✅
  - The console object provides the log() method for outputting debug information to the terminal.
- `debug.write()`
  - Standard JavaScript uses the console object rather than a global debug object for logging.
- `terminal.out()`
  - Terminal output in the browser is standardized through the console API methods.

**Hint:** Starts with "c".

### 6. What is the purpose of "document.querySelector()"

- Modifying the page window
  - Window modifications are handled via the window object, not the document selector.
- **Selecting an element by CSS** ✅
  - This method returns the first element that matches a specified CSS selector string.
- Creating new script tags
  - Creating elements is done via document.createElement() rather than a query selector.
- Refreshing the document
  - Page refreshing is controlled by the location.reload() method in the browser.

**Hint:** It interacts with the HTML page.

### 7. Which of these is NOT a valid way to declare a variable in modern JS?

- `let`
  - The "let" keyword is the standard method for declaring variables with block scope.
- **`set`** ✅
  - The "set" keyword is used to define object setters and is not a variable declaration tool.
- `var`
  - While legacy and generally avoided, "var" remains a valid keyword for function-scoped variables.
- `const`
  - The "const" keyword is used to declare variables that cannot be reassigned after initialization.

**Hint:** One of these is from a different language.

### 8. What is a "Promise" in JavaScript?

- A syntax for error suppression
  - Errors are handled within promises using .catch(), but they are not for general suppression.
- **An object for async task state** ✅
  - A Promise represents the eventual result of an asynchronous operation and its resulting value.
- A lock for immutable variables
  - Variable immutability is handled by the "const" keyword or the Object.freeze() method.
- A server-side validation rule
  - Promises are a client-side or environment-side control flow tool, not a validation protocol.

**Hint:** Used for asynchronous operations.

### 9. Which array method creates a new array by performing a function on every element?

- `forEach()`
  - The forEach() method iterates over items but does not return a new array result.
- **`map()`** ✅
  - The map() method transforms each element and returns a new array containing the results.
- `filter()`
  - The filter() method creates a subset of an array based on a condition without transforming values.
- `push()`
  - The push() method modifies the original array by adding an element to the end of it.

**Hint:** It "maps" values to new values.

### 10. What does the "this" keyword refer to in a standard object method?

- The root execution context
  - In a method, "this" is bound to the object instance rather than the root window context.
- **The object owning the method** ✅
  - The "this" keyword allows a method to access other properties and methods on the same object.
- The internal prototype chain
  - While "this" can access inherited properties, it refers to the object instance itself.
- The parent function caller
  - JavaScript does not use "this" to refer to the function that called the current method.

**Hint:** It refers to the owner.

### 11. How do you convert a JSON string into a JavaScript object?

- `JSON.stringify()`
  - The stringify method converts a JavaScript object into a JSON-formatted string.
- **`JSON.parse()`** ✅
  - The parse method takes a JSON string and converts it into a native JavaScript object.
- `Object.convert()`
  - JavaScript does not have a global convert method on the Object prototype for JSON.
- `String.toJSON()`
  - Standard strings do not have an internal method for converting themselves to JSON objects.

**Hint:** You "parse" the string.

### 12. What is "Hoisting" in JavaScript?

- Uploading files to a server
  - Transferring files to a server is known as deployment or uploading, not hoisting.
- **Moving declarations to the top** ✅
  - Hoisting is the default behavior of moving declarations to the top of the current scope.
- Increasing memory allocation
  - Memory management is handled by the garbage collector and engine, not by hoisting logic.
- Optimizing function calls
  - While related to execution phase, hoisting is about scope visibility rather than optimization.

**Hint:** Variables and functions being moved to the top.

### 13. Which operator is used to spread the elements of an array into another array?

- **`...`** ✅
  - The spread operator (...) expands an iterable into individual elements within a new array.
- `***`
  - Triple asterisks are not valid operators within the JavaScript language specification.
- `&&&`
  - Logical AND uses two symbols (&&); three symbols are not a recognized JavaScript operator.
- `!!!`
  - While single and double exclamation marks are used for coercion, triple marks have no special function.

**Hint:** Three dots.

### 14. What is an "anonymous function"?

- A function with hidden code
  - All JavaScript function logic is visible; anonymity refers only to the identifier name.
- **A function without a name** ✅
  - Anonymous functions are defined without a title and are often used as immediate callbacks.
- A function that only runs once
  - Any function can be limited to one run, but anonymity does not impose this restriction.
- A function for private scopes
  - Privacy is achieved via closures or private class members, not via anonymous naming.

**Hint:** A function with no name.

### 15. Which of these is a "falsy" value in JavaScript?

- `"0"`
  - A non-empty string is considered truthy in JavaScript, even if it contains the character "0".
- **`0`** ✅
  - The numeric value 0 is one of the standard falsy values defined in the language engine.
- `[]`
  - Empty arrays are objects in JavaScript and are evaluated as truthy in boolean contexts.
- `{}`
  - Empty objects are considered truthy; they must be checked for keys to determine if they are "empty".

**Hint:** Something that behaves like False in an "if" statement.

### 16. What is the purpose of the "async" keyword?

- To increase processing speed
  - The async keyword manages concurrency and waiting without increasing the raw execution speed.
- **To return a Promise object** ✅
  - Functions marked with async always return a Promise and allow the use of the await keyword.
- To encrypt server requests
  - Encryption is handled by networking protocols like HTTPS, not by the async keyword.
- To bypass the event loop
  - Async functions operate within the event loop to manage non-blocking task execution.

**Hint:** It prepends a function definition.

### 17. How do you check the length of an array "myArr"?

- `myArr.count()`
  - The count() method is common in C# or Swift, but it is not a native JavaScript array method.
- **`myArr.length`** ✅
  - The length property returns the number of elements currently stored in the array.
- `myArr.size`
  - The size property is used for Map and Set collections, while arrays use length.
- `len(myArr)`
  - The len() function is a Python built-in and is not part of the JavaScript global scope.

**Hint:** Property name.

### 18. What does "DOM" stand for?

- Data Object Model
  - While the DOM represents data, the official acronym uses "Document" for the first letter.
- **Document Object Model** ✅
  - The DOM is the structural representation of the HTML document as a tree of objects.
- Digital Ordinary Map
  - This is an incorrect expansion; the term refers specifically to the document structure.
- Direct Output Mode
  - This refers to rendering or buffer modes rather than the document object structure.

**Hint:** The structure of the webpage.

### 19. Which keyword is used to stop a loop immediately?

- `stop`
  - JavaScript does not recognize "stop" as a valid keyword for controlling loop iteration.
- **`break`** ✅
  - The "break" keyword terminates the current loop and resumes execution after the loop block.
- `exit`
  - The "exit" command is typically used in shell scripting or to terminate a full process.
- `halt`
  - While "halt" implies stopping, it is not a reserved keyword for loop control in JavaScript.

**Hint:** Same as in Java or Python.

### 20. What is the "event bubble"?

- A visual tooltip element
  - Bubbling refers to the internal propagation of events, not to a user interface component.
- **Event propagation upwards** ✅
  - Event bubbling describes how an event moves from the target element up through its parents.
- A browser memory error
  - Bubbling is a standard architectural feature of the DOM event model, not a memory fault.
- A recursive function call
  - While it involves a sequence of triggers, bubbling is handled by the browser event engine.

**Hint:** How events travel up the DOM.

### 21. Which symbol is used for template literals?

- `Double quotes (" ")`
  - Double quotes create standard strings and do not support native expression interpolation.
- **`Backticks (` `)`** ✅
  - Backticks define template literals, allowing for multi-line strings and embedded variables.
- `Single quotes (' ')`
  - Single quotes are functionally similar to double quotes and lack template literal features.
- `Tildes (~ ~)`
  - The tilde is a bitwise NOT operator and is not used to encapsulate string literals.

**Hint:** The key next to the "1".

### 22. What is the purpose of "use strict"?

- To encrypt source code
  - Strict mode focuses on code quality and error prevention rather than source security.
- **To enforce cleaner code** ✅
  - Enabling strict mode catches common silent errors and prevents the use of unsafe features.
- To allow legacy support
  - Strict mode actually disables some legacy features to promote modern coding standards.
- To minify script files
  - Minification is a build-step process, while "use strict" is a runtime directive for the engine.

**Hint:** It makes JS less "loose".

### 23. What is "null" in JavaScript?

- An undeclared variable
  - Undeclared variables result in a ReferenceError, whereas "null" is an assigned value.
- **Intentional empty value** ✅
  - The "null" value is used by developers to explicitly signal that a variable has no object value.
- The numeric value of 0
  - While 0 is falsy, "null" is a distinct primitive type representing the absence of an object.
- A boolean false state
  - Although falsy in conditional checks, "null" is not the same as the boolean "false".

**Hint:** An intentional absence.

### 24. Which method adds an item to the BEGINNING of an array?

- `push()`
  - The push() method adds elements to the end of the array, increasing its length.
- **`unshift()`** ✅
  - The unshift() method adds one or more elements to the start of an array and shifts others.
- `shift()`
  - The shift() method removes the first element from an array rather than adding a new one.
- `prepend()`
  - While prepend() exists for DOM nodes, standard JavaScript arrays use the unshift() method.

**Hint:** The opposite of push.

### 25. What does "NaN" stand for?

- Null and Negative
  - Null and Negative are distinct numeric states, while NaN represents an undefined result.
- **Not a Number** ✅
  - NaN is a numeric data type value that represents an undefined or unrepresentable mathematical result.
- No active Network
  - Networking status is not related to the NaN numeric type in JavaScript core.
- New assigned Node
  - The DOM uses Node objects, but NaN is strictly related to numeric operations.

**Hint:** Not A...

### 26. Which function is used to execute a block of code after a specified delay?

- `setInterval()`
  - The setInterval() function repeats the code execution indefinitely at a fixed time interval.
- **`setTimeout()`** ✅
  - The setTimeout() function executes the provided code once after the specified delay in milliseconds.
- `wait()`
  - JavaScript does not provide a native wait() function; delays are managed via timers or promises.
- `sleep()`
  - The sleep() function is common in Python or C but is not a native JavaScript keyword.

**Hint:** One-time delay.

### 27. How do you check if an object has a specific property?

- `object.exists(key)`
  - There is no native .exists() method for checking property presence on standard objects.
- **`key in object`** ✅
  - The "in" operator returns true if the specified property exists in the object or its prototype chain.
- `object.contains(key)`
  - The .contains() method is used for DOM node hierarchy checks, not for object property keys.
- `object.has(key)`
  - While .has() is used for Map and Set collections, standard objects do not use this method.

**Hint:** Checks the keys.

### 28. What is a "Closure"?

- Closing browser window
  - Closing a window is a browser environment event and not a functional programming concept.
- **Persistent scope access** ✅
  - A closure is a function that retains access to its lexical scope even after that scope has closed.
- Ending a loop execution
  - Loop termination is handled by conditions or the "break" keyword, not by closures.
- A private API endpoint
  - Endpoints are networking concepts; a closure is an internal variable-scoping mechanism.

**Hint:** A function remembering its home.

### 29. Which keyword is used to inherit from another class?

- `inherits`
  - While accurate as a description, "inherits" is not a reserved keyword in JavaScript class syntax.
- **`extends`** ✅
  - The "extends" keyword is used in class declarations to create a class that is a child of another.
- `implements`
  - The "implements" keyword is used in TypeScript and Java but is not part of the standard JS class model.
- `super`
  - The "super" keyword is used to call functions on an object's parent, not to declare the inheritance itself.

**Hint:** It "extends" the functionality.

### 30. What is the default return value of a function that doesn't return anything?

- `null`
  - The "null" value must be returned explicitly and is not the default result for empty functions.
- **`undefined`** ✅
  - JavaScript automatically returns "undefined" if no specific return statement is executed.
- `false`
  - Functions do not default to boolean values unless they are specifically designed as predicates.
- `0`
  - The numeric value 0 is never the default return for a function without a return statement.

**Hint:** It is not defined.
