menu

JavaScript Basics


1. 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.


2. Which of the following is a valid way to create a function in JavaScript?

function myFunction() {}

var myFunction = function() {};

const myFunction = () => {};

all of the above


3. 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.


4. 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.


5.

What is the output of the following code?

console.log("hello".toUpperCase());

HELLO

hello

undefined

null


6. What is the difference between == and === in JavaScript?

There is no difference between == and ===.

== performs a strict comparison, while === performs a loose comparison.

=== performs a strict comparison, while == performs a loose comparison.

== and === both perform a strict comparison.


7. Which of the following is not a looping structure in JavaScript?

for

while

do-while

repeat


8. What does the typeof operator return for null in JavaScript?

null

undefined

object

number


9. 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.


10.

What is the output of the following code?

console.log("2" * "3");

5

6

23

6