0% found this document useful (0 votes)
1K views

Basic_JavaScript_Interview_Questions_Answers

Uploaded by

Aditya Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Basic_JavaScript_Interview_Questions_Answers

Uploaded by

Aditya Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Basic JavaScript Interview Questions - Answers

1. What is JavaScript?

JavaScript is a high-level, interpreted programming language used to make web pages interactive. It

is primarily used for client-side scripting, but can also be used on the server-side (Node.js).

2. What are the different data types in JavaScript?

The basic data types in JavaScript are:

- Primitive Types: String, Number, BigInt, Boolean, undefined, null, Symbol

- Non-primitive Type: Object (arrays, functions, dates, etc.)

3. What are `var`, `let`, and `const` in JavaScript?

var: Function-scoped or globally scoped (prior to ES6).

let: Block-scoped variable, can be reassigned.

const: Block-scoped variable, cannot be reassigned.

4. What is the difference between `null` and `undefined`?

undefined: A variable is declared but not assigned any value, or a function does not return a value.

null: Explicitly assigned to indicate that a variable has no value.

5. What are the different types of operators in JavaScript?

Arithmetic Operators: +, -, *, /, %, ++, --

Comparison Operators: ==, ===, !=, !==, >, <, >=, <=

Logical Operators: &&, ||, !

Assignment Operators: =, +=, -=, *=, /=

Ternary Operator: condition ? value_if_true : value_if_false

6. What is the difference between `==` and `===` in JavaScript?

`==` (Loose equality): Compares values after converting them to a common type.
`===` (Strict equality): Compares both values and types.

7. What is a closure in JavaScript?

A closure is a function that retains access to its lexical scope, even when the function is executed

outside that scope.

8. Explain event delegation in JavaScript.

Event delegation is a technique where an event listener is attached to a parent element, and the

event is handled by checking the `event.target` to identify which child element triggered the event.

9. What are JavaScript functions and how are they created?

A function is a block of code that can be called to perform a task. It can be created using:

- Function declaration: function myFunction() {}

- Function expression: const myFunction = function() {};

- Arrow function: const myFunction = () => {};

10. What is hoisting in JavaScript?

Hoisting is JavaScript's default behavior of moving declarations (but not initializations) to the top of

their containing scope during the compile phase.

11. What is the `this` keyword in JavaScript?

The `this` keyword refers to the context in which the current function is executed. Its value depends

on how the function is called.

12. What is the DOM (Document Object Model)?

The DOM is an interface that represents HTML and XML documents as a tree structure where each

node is an object representing a part of the document.

13. What is the difference between synchronous and asynchronous code?

Synchronous: The code is executed line-by-line, and each task must complete before the next one
begins.

Asynchronous: The code can execute tasks in parallel without blocking the next task.

14. What is a callback function?

A callback function is a function passed as an argument to another function that is executed later,

once the task in the parent function completes.

15. What is the difference between `setTimeout()` and `setInterval()`?

`setTimeout()`: Executes a function once after a specified delay.

`setInterval()`: Executes a function repeatedly with a specified interval.

You might also like