You are on page 1of 2

1. What is the difference between == and === in JavaScript?

 The double equals (==) operator checks if two values are equal, while ignoring their
data types. The triple equals (===) operator checks if two values are equal and also
checks their data types.

2. What are the different data types in JavaScript?


 JavaScript has six primitive data types: undefined, null, boolean, number, string, and
symbol. It also has one non-primitive data type: object.

3. What is hoisting in JavaScript?


 Hoisting is the process by which variable declarations and function declarations are
moved to the top of their respective scopes.

4. What is closure in JavaScript?


 A closure is a function that has access to variables in its outer function, even after the
outer function has returned.

5. How do you declare a variable in JavaScript?


 You can declare a variable in JavaScript using the var, let, or const keywords, followed
by the variable name and an optional initial value.

6. What is an array in JavaScript and how do you create one?


 An array is a collection of values, stored in a single variable. You can create an array
in JavaScript by enclosing a comma-separated list of values in square brackets, like
this: var myArray = [1, 2, 3];

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


 The var keyword is used to declare a variable with function scope, while the let and
const keywords are used to declare variables with block scope. The difference
between let and const is that let variables can be reassigned, while const variables
cannot.

8. What is the difference between a function declaration and a function expression in


JavaScript?
 A function declaration is a statement that defines a named function, while a function
expression is an expression that defines an anonymous function.

9. How do you loop through an array in JavaScript?


 You can loop through an array in JavaScript using a for loop, a for...of loop, or a
forEach() method.

10. How do you handle errors in JavaScript?


 You can handle errors in JavaScript using try...catch statements, which allow you to
catch and handle exceptions that might be thrown by your code.

You might also like