menu

JavaScript Basics


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


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

The global object

The parent object

The current object

The child object


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

console.log(typeof null);

string

number

object

null


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


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

for loop

while loop

do-while loop

if statement


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


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


9.

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;


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