DEV Community

Cover image for 50+ JavaScript Interview Questions
Sandip Bandgar
Sandip Bandgar

Posted on

50+ JavaScript Interview Questions

Level: Beginner to Intermediate
Topics:

➊ Functions Basics
➋ Function Declarations
➌ Function Scope
➍ Function Arguments
➎ Function Expressions
➏ Arrow Functions
➐ Higher Order Function & Callbacks
➑ Closure
➒ IIFE
➓ Global Functions

➀ Does JavaScript allow function overloading?

➁ What does it mean, "In JavaScript, functions are first-class citizens"?

➂ What are the different ways of defining a function?

➃ Can a function name be used as a normal variable?

➄ What is the difference between "myFunction" and "myFunction()"?

➅ Does every function in JavaScript return something even if not explicitly stated? If yes, what does it return by default?

➆ Can a function return multiple values? What tricks can you apply?

➋ Function Declarations

➀ What are function declarations or, function statements?

➁ Are function declarations always hoisted?

➂ Can a function be declared inside another function?

➌ Function Scope

➀ What is a function scope or a local scope?

➁ How does hoisting work inside a function body?

➂ Among var, let, and const, which allows hoisting?

➃ What is block scope and, how is it different from function scope?

➍ Function Arguments

➀ What is the difference between function parameters and function arguments?

➁ What is "arguments" reference inside a function body? What purpose does it solve?

➂ Is "arguments" an array? Explain its behaviour.

➃ What is a "Variadic Function"?

➄ What are different ways to access a variable number of arguments passed to a function inside its body?

➅ What is a rest parameter operator? How does it work inside the function's parameters list?

➆ Define some valid and invalid use cases of the rest parameter.

➇ Define significant differences between "arguments" and "a rest parameter".

➎ Function Expressions

➀ What is a function expression?

➁ How is a function expression different from a function declaration?

➂ Are function expressions hoisted?

➃ What is a named function expression?

➄ What is an unnamed function expression?

➅ Give some example use cases for using function expressions instead of function statements.

➏ Arrow Functions

➀ What is an arrow function?

➁ Which ECMAScript version introduced the arrow function?

➂ Given a normal function, convert it into an arrow function.

➃ When is it not mandatory to include arguments inside ( and ) in an arrow function?

➄ When does an arrow function return implicitly even if no return keyword is specified?

➅ What are some key differences between a normal and an arrow function?

➐ Higher Order Function & Callbacks

➀ What is a callback function?

➁ Highlight some use cases for callback functions.

➂ Mention a few in-built functions that accept a callback.

➃ What is a higher-order function (HOF)?

➑ Closure

➀ Define closure.
➁ When does JavaScript create a closure?
➂ What is a lexical scope?
➃ Define various scopes within a closure.
➄ Why do you think closure is useful?
➅ Highlight a few disadvantages of closures.

➒ IIFE

➀ What is IIFE?

➁ Highlight some use cases of IIFE.

➂ Why do we see less usage of IIFE these days? What are its alternatives?

➓ Global Functions

➀ Which function should we use to delay the execution of some piece of code?

➁ What is setTimeout()? Define what parameters it accepts.

➂ Will setTimeout(code, 0) make execute the code immediately?

➃ How to cancel the scheduled execution?

➄ Which function should we use to execute some piece of code repetitively at some time interval?

➅ What is setInterval()? Define what parameters it accepts.

➆ How to stop the timed and repetitive execution of code specified by setInterval()?

Top comments (4)

Collapse
 
urstrulyvishwak profile image
Kurapati Mahesh

Great Collection.

My Article about:

  1. ➐ Higher Order Function & Callbacks
Collapse
 
moazamdev profile image
Moazam Ali

Great selection of questions 👌

Collapse
 
yemiklein profile image
Adeyemi Raji

how about if you drop the answers to the questions

Collapse
 
sandip_bandgar profile image
Sandip Bandgar

it would take long time to compile all answers & put it together.. that's why I didn't add it