Unlock hundreds more features
Save your Quiz to the Dashboard
View and Export Results
Use AI to Create Quizzes and Analyse Results

Sign inSign in with Facebook
Sign inSign in with Google

JavaScript Intermediate Practice Quiz

Sharpen your coding skills with practical questions

Difficulty: Moderate
Grade: Grade 11
Study OutcomesCheat Sheet
Paper art illustrating a trivia quiz for The JS Intermediate Challenge

What is the output of console.log(typeof null) in JavaScript?
number
object
null
 
The typeof operator returns 'object' for null due to a historical bug in JavaScript. This behavior is widely recognized and important when performing type checks.
Which statement correctly describes a closure in JavaScript?
A closure is a function that only runs once and then is immediately discarded.
A closure is a method for handling asynchronous operations.
A closure is an inner function that has access to variables of its outer function even after the outer function has returned.
A closure is an object used to store private data.
Closures allow an inner function to access variables from its outer (enclosing) function even after the outer function has finished executing. This is a fundamental concept in JavaScript that enables private data and state retention.
What is the primary purpose of the 'use strict'; declaration in JavaScript?
It converts JavaScript into a strongly typed programming language.
It enables strict mode which helps catch common coding errors and prevents the use of potentially unsafe actions.
It turns off all error messages and allows deprecated code to run.
It automatically optimizes the code for faster performance.
The 'use strict' directive enables strict mode in JavaScript, which turns previously accepted bad practices into errors. This helps developers catch mistakes and write safer, more secure code.
Which array method is used to create a new array by applying a function to each element of an existing array?
reduce
forEach
filter
map
The map() method creates a new array by calling a provided function on every element of the original array. It is a fundamental tool for transforming arrays in JavaScript.
What is the result of the expression 2 + '2' in JavaScript?
4
NaN
Error
22
In JavaScript, when a number and a string are added together using the '+' operator, type coercion occurs and the number is converted to a string. The two strings are concatenated, resulting in '22'.
In a regular function invocation in non-strict mode, what does the 'this' keyword refer to?
Undefined
The global object (window in browsers)
The function itself
The object on which the method was called
In non-strict mode, when a function is invoked without an explicit context, the 'this' keyword defaults to the global object (window in browsers). This behavior is essential to understand when dealing with function calls in JavaScript.
What is a reliable way to explicitly convert the string '123' into a number in JavaScript?
'123'
Number('123')
parseInt('123abc')
String('123')
Using Number('123') explicitly converts the string '123' into a number. This approach is clear and reliable for converting valid numeric strings, in contrast to methods that may return partial results or remain as strings.
Which statement best describes JavaScript's event loop?
It converts synchronous code into asynchronous events.
It manages asynchronous callbacks by placing them in a queue that is processed once the call stack is empty.
It waits for all asynchronous operations to complete before executing any code.
It immediately executes asynchronous code in parallel with synchronous code.
The event loop continuously checks if the call stack is empty and then processes tasks from the callback queue. This mechanism allows JavaScript to handle asynchronous operations without blocking the main execution thread.
What does console.log(0.1 + 0.2 === 0.3) output in JavaScript, and why?
false, due to floating point precision errors
0, because the result rounds down
true, because arithmetic is accurate in JavaScript
NaN, because the calculation fails
Due to floating point imprecision, the sum of 0.1 and 0.2 does not exactly equal 0.3, resulting in a false comparison. This is a well-known issue in many programming languages that use binary floating point arithmetic.
What is hoisting in JavaScript?
A technique used to optimize memory usage by cleaning up unused variables.
A method for accelerating code execution by pre-compiling functions.
The process of encrypting code for secure transmission.
The behavior in which variable and function declarations are moved to the top of their scope before code execution.
Hoisting is the JavaScript mechanism where variable and function declarations are moved to the top of their corresponding scope during the compile phase. This means that they can be referenced before their actual declaration in the code, though only the declaration is hoisted, not the initialization.
Which method is used to add one or more elements to the end of an array in JavaScript?
push
shift
pop
unshift
The push() method appends one or more elements to the end of an array and returns the new length of the array. It is one of the most commonly used methods for modifying arrays in JavaScript.
What is the key difference between var and let declarations in JavaScript?
var and let are equivalent in scope but let allows duplicate declarations.
let is block scoped while var is function scoped.
Both var and let are function scoped, but let is hoisted differently.
var is block scoped while let is function scoped.
Let, introduced in ES6, is block scoped, meaning it is only accessible within the nearest set of curly braces. In contrast, var is function scoped, which can lead to unexpected behavior when used in loops and conditional statements.
Which JavaScript method serializes a JavaScript object into a JSON string?
object.toString()
JSON.convert
JSON.parse
JSON.stringify
JSON.stringify converts a JavaScript object or value to a JSON string, making it useful for data transmission and storage. This method is a key tool when working with APIs and local storage.
What is the purpose of the 'finally' block in exception handling?
It executes code after try and catch blocks, regardless of whether an exception was thrown.
It terminates the program if an error is detected.
It retries the code block if an error occurs.
It catches any errors that were not caught in the try block.
The finally block is executed after the try and catch blocks regardless of whether an exception has occurred. It is typically used for cleanup tasks that must always be performed, such as releasing resources.
Which best describes a promise in JavaScript?
A placeholder that immediately returns the final value of a computation.
A loop that waits for a callback function to finish.
An object representing the eventual result of an asynchronous operation.
A function that executes synchronously to handle asynchronous errors.
A promise acts as a placeholder for a value that may be available in the future as the result of an asynchronous operation. It allows developers to handle asynchronous events more cleanly compared to traditional callback-based approaches.
How does prototypal inheritance work in JavaScript?
It uses a copy mechanism to replicate properties from one object to another.
Classes inherit properties from objects via a constructor function.
It only applies to primitive data types and not objects.
Objects inherit properties and methods from other objects through a prototype chain.
Prototypal inheritance in JavaScript lets objects inherit properties and methods from other objects by linking to them via a prototype chain. This system is distinct from classical inheritance and is a core feature of JavaScript's object model.
What is memoization in JavaScript and how does it improve performance?
Memoization is a technique where the results of function calls are cached to avoid redundant computations.
Memoization splits functions into smaller parts for easier debugging.
Memoization encrypts function outputs to secure data.
Memoization automatically formats code for better readability.
Memoization involves caching the results of expensive function calls so that repeated calls with the same input can return the cached result immediately. This optimization technique can greatly enhance performance, especially in recursive and computationally intensive operations.
Which scenario best demonstrates the use of an Immediately Invoked Function Expression (IIFE)?
Using an IIFE to create a private scope and execute code immediately to avoid polluting the global namespace.
Defining a function for later execution after an event occurs.
Using a function as a method in an object literal.
Creating an asynchronous operation with callbacks.
An IIFE is executed immediately after its definition, which creates a private scope for variables and functions. This pattern helps prevent global namespace pollution and potential naming conflicts in larger codebases.
How can currying be applied to JavaScript functions?
It eliminates the need for higher-order functions entirely.
It combines two variable values into one.
It transforms a function with multiple arguments into a sequence of functions each taking a single argument.
It compresses multiple functions into a single function to optimize space.
Currying transforms a function that takes multiple arguments into a series of functions that each take a single argument. This approach allows for partial application of functions and can simplify complex function calls by breaking them into simpler steps.
What is the difference between synchronous and asynchronous code execution in JavaScript?
Synchronous code executes sequentially, blocking further execution until each operation completes; asynchronous code allows concurrent operations without blocking the main thread.
Synchronous code runs on a separate thread, while asynchronous code runs on the main thread.
There is no practical difference as both execute in the same order.
Asynchronous code always executes before synchronous code due to prioritization.
Synchronous code runs line by line, meaning each operation must complete before the next one begins, which can block further execution. In contrast, asynchronous code initiates operations and then moves on, allowing the main thread to remain unblocked and handle other tasks concurrently.
0
{"name":"What is the output of console.log(typeof null) in JavaScript?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"What is the output of console.log(typeof null) in JavaScript?, Which statement correctly describes a closure in JavaScript?, What is the primary purpose of the 'use strict'; declaration in JavaScript?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}

Study Outcomes

  1. Analyze real-world JavaScript scenarios to identify underlying errors and logic issues.
  2. Apply intermediate coding techniques to solve practical programming challenges.
  3. Understand core JavaScript concepts such as closures, event handling, and prototype inheritance.
  4. Develop effective debugging strategies to improve code quality in test environments.
  5. Synthesize multiple coding approaches to optimize solution performance and reliability.

JavaScript Quiz for Intermediate Cheat Sheet

  1. Mastering JavaScript Functions - Get comfortable with function declarations, expressions, and concise arrow functions that make your code shine. Harness higher-order functions like map(), filter(), and reduce() to slice and dice arrays in a flash. Ready to transform data effortlessly? Functions - MDN Web Docs
  2. Exploring Asynchronous JavaScript - Dive into Promises and async/await syntax for non-blocking code that reads like magic. Manage API calls and timers gracefully without drowning in callback chaos. Say goodbye to callback hell! Asynchronous JavaScript - MDN Web Docs
  3. Understanding the Event Loop - Peek under the hood to see how JavaScript handles tasks, microtasks, and timers in its event loop. This knowledge supercharges your debugging and performance optimization skills. Get ready to write faster, smoother apps! Event Loop - MDN Web Docs
  4. Delving into Object-Oriented Programming (OOP) - Explore constructors, prototypes, and ES6 classes to model real-world entities in code. Learn inheritance patterns to build scalable and maintainable applications. Bring your code architecture to the next level! Object-Oriented Programming - MDN Web Docs
  5. Utilizing the "this" Keyword - Master how this changes based on invocation context, whether in global scope, object methods, or event handlers. Avoid common pitfalls and keep your methods pointing to the right object. Understanding this unlocks cleaner, less confusing code! this - MDN Web Docs
  6. Implementing Modules with Import/Export - Break your code into reusable chunks using ES6 modules, improving clarity and collaboration. Use export to share utilities and import to plug them in wherever needed. Modular code makes scaling a breeze! Modules - MDN Web Docs
  7. Mastering Destructuring and Spread/Rest Operators - Extract values from arrays or objects with elegant destructuring syntax and combine data effortlessly with spread/rest operators. Turn verbose loops into clean one-liners. Your refactored code will thank you! Destructuring Assignment - MDN Web Docs
  8. Exploring Functional Programming Concepts - Embrace immutability, pure functions, and function composition to write predictable code free from side effects. Level up your array transformations and state management skills. Functional patterns lead to robust applications! Functions - MDN Web Docs
  9. Understanding Scope and Closures - Grasp how local, block, and global scopes affect variable access and how closures preserve data across calls. Use closures to create private variables and maintain state. Master scope to write safer, bug-free code! Closures - MDN Web Docs
  10. Handling Errors with Try/Catch - Learn to anticipate and manage exceptions using try...catch blocks, keeping your app running smoothly. Enhance reliability with custom error messages and cleanup logic. Error handling turns crashes into graceful recoveries! try...catch - MDN Web Docs
Powered by: Quiz Maker