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 output of the following code?

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

5

6

23

6


3.

What is the output of the following code?

console.log(2 + 2 + "2");

42

22

221

4


4. What is the purpose of the try-catch statement in JavaScript?

To define a new variable.

To execute a block of code and catch any errors that might occur.

To create a loop.

To exit a function.


5.

What is the output of the following code?

console.log(3 + "2");

5

32

6

23


6. Which of the following is a primitive data type in JavaScript?

Number

Array

Object

Function


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


8. Which of the following is not a way to loop through an array in JavaScript?

for loop

while loop

do-while loop

if statement


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


10. Which of the following is not a primitive data type in JavaScript?

string

number

boolean

object