menu

JavaScript Basics


1.

What is the output of the following code?

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

5

6

23

6


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. Which of the following is a valid way to declare a variable in JavaScript?

variable name = value;

var name = value;

let name = value;

all of the above


4. What is the difference between let and const in JavaScript?

There is no difference between let and const.

let is block-scoped, while const is function-scoped.

const is block-scoped, while let is function-scoped.

const can only be used to declare global variables.


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


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


7. What is the difference between let and var in JavaScript?

There is no difference between let and var.

let is block-scoped, while var is function-scoped.

var is block-scoped, while let is function-scoped.

let can only be used to declare global variables.


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


9.

What is the output of the following code?

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

HELLO

hello

undefined

null


10.

What is the output of the following code?

console.log(typeof null);

string

number

object

null