menu

JavaScript Basics


1. What is the difference between a function declaration and a function expression in JavaScript?

There is no difference between a function declaration and a function expression.

A function declaration is hoisted to the top of the scope, while a function expression is not hoisted.

A function expression is hoisted to the top of the scope, while a function declaration is not hoisted.

A function declaration can only be used inside of an object, while a function expression can be used anywhere.


2. What is the difference between synchronous and asynchronous programming in JavaScript?

There is no difference between synchronous and asynchronous programming.

Synchronous programming executes code in a single thread, while asynchronous programming allows for code to be executed in multiple threads.

Synchronous programming executes code one line at a time, while asynchronous programming allows for code to be executed out of order.

Synchronous programming executes code in a predetermined order, while asynchronous programming allows for code to be executed out of order.


3. What is the purpose of the this keyword in JavaScript?

To refer to the global object.

To refer to the parent object.

To refer to the child object.

To refer to the current object.


4. What is the difference between a for loop and a while loop in JavaScript?

There is no difference between a for loop and a while loop.

A for loop is used for counting and iterating over a range of values, while a while loop is used for executing a block of code while a condition is true.

A while loop is used for counting and iterating over a range of values, while a for loop is used for executing a block of code while a condition is true.

A for loop is used for executing a block of code while a condition is true, while a while loop is used for counting and iterating over a range of values.


5. What does the isNaN() function in JavaScript do?

Determines if a value is a number or not.

Determines if a value is a string or not.

Determines if a value is undefined or not.

Determines if a value is null or not.


6.

What is the output of the following code?

console.log(typeof null);

string

number

object

null


7. What does the keyword this refer to in JavaScript?

The global object

The parent object

The current object

The child object


8. What is the difference between null and undefined in JavaScript?

There is no difference between null and undefined.

null is a value that represents an empty object reference, while undefined is a value that represents an uninitialized variable.

undefined is a value that represents an empty object reference, while null is a value that represents an uninitialized variable.

null and undefined both represent an uninitialized variable.


9. What does the delete operator do in JavaScript?

Deletes a variable

Deletes a property of an object

Deletes an element from an array

Deletes a function


10.

What is the output of the following code?

console.log(3 === "3");

1

0

NaN

null