menu

JavaScript Basics


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


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


3.

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;


4.

What is the output of the following code?

var x = 5;
var y = 2;
console.log(x % y);

2

2.5

3

1


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


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

The global object

The parent object

The current object

The child object


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

Number

Array

Object

Function


9. What is a callback function in JavaScript?

A function that is called when an error occurs.

A function that is called when a button is clicked.

A function that is passed as an argument to another function and is called when the first function has finished executing.

A function that is used to generate random numbers.


10.

What is the output of the following code?

console.log(typeof null);

string

number

object

null