menu

JavaScript Basics


1. What is the purpose of the return statement in a JavaScript function?

To define the arguments for the function.

To declare a variable.

To exit the function and return a value.

To create a loop.


2.

What is the output of the following code?

console.log(3 + "2");

5

32

6

23


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


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


5.

Which of the following is not a valid way to declare a variable in JavaScript?

var myVar = 5;

let myVar = 10;

const myVar = "hello";

myVar = true;


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

null

undefined

object

number


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


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

string

number

boolean

object


9.

What is the output of the following code?

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

42

22

221

4


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