Skip to main content

JavaScript Interview Questions

1. What is JavaScript?

JavaScript is a dynamic programming language, a scripting language used to develop web applications, games, and more. It allows us to implement dynamic features on web pages that cannot do with just HTML and CSS.

2. Is JavaScript is case sensitive? Explain its example.

Yes , For Ex. Variable names are case-sensitive, which means "name" and "Name" are considered different variables.

3. What are the features of JavaScript?

1. High-Level Language
2. Interpreted Language
3. Asynchronous Programming
4. DOM Manipulation

4. What is let keyword in javascript?

1. Let keyword used to declare variables in JavaScript.

<script>
let age = 20;
console.log(age);
</script>

In the above example, the let is used to declare variable age.

  1. Variables defined using let Cannot be re-declared within the same scope.
<script>
let age = 20;
console.log(age);
let age = 30;
console.log(age);
</script>

output : Uncaught SyntaxError: Identifier 'age' has already been declared

In the above example, the age is used to re-declare in same scope. so it show the error massage .

5. What is the console.log() function in JavaScript?

1. Debugging: You can use it to print variable values, intermediate results, or the flow of your program to the console. This helps you identify and fix issues in your code.
2. Inspecting Data: You can log the contents of variables, arrays, objects, or any JavaScript data type to examine their values and structures.

6. What is the use of the alert() function in JavaScript?

The alert() function is a built-in JavaScript function that displays a simple dialog box or popup in the user's web browser with a specified message. This message is often used to convey important information, warnings, or prompts to the user. The user needs to acknowledge the alert by clicking the `OK`` button before they can continue interacting with the web page.

7. How do you add JavaScript in html element?

You can Add JavaScript in Html elements using script tag.

<script></script>

8. How do you declare a variable in JavaScript?

In JavaScript , you can declare a variable using one of three keywords `var` `let` and `const`. The choice of which keyword to use depends on the variable's intended scope and whether it should be changeable or constant .

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

Difference between var, let and const​

var​

  • The scope of the var variable is the functional scope.

  • It can be updated and re-declared in scope.

  • It can be declared without initialization.

  • It can be accessed without initialization because its default value is undefined.

let​

  • Let allow us to declare a variable that is limited to the scope of a block.

  • In let first we declare variable and second time we used so there is no need to write second time.

  • It can be declared without initialization.

  • It cannot accessed without initialization, or a "reference error" will be raised.

const​

  • The scope of the const variable is block scope.

  • It cannot be updated or re-declared in scope.

  • It cannot be accessed without initialization because it cannot be declared without initialization.

10. How do you check the type of a variable in JavaScript?

You can check the type of a variable in JavaScript using the `typeof` operator. The typeof operator returns a string that represents the data type of the operand.

let variable = 42;
console.log(typeof variable); // Output: "number"

let text = "Hello, world!";
console.log(typeof text); // Output: "string"

let isTrue = true;
console.log(typeof isTrue); // Output: "boolean"

let fruits = ["apple", "banana", "cherry"];
console.log(typeof fruits); // Output: "object"

11. Is it possible to break JavaScript Code into several lines?

"Yes, it's completely possible and often a good idea to divide your JavaScript code into multiple lines. This is done to make your code easier to read and maintain. JavaScript is quite forgiving when it comes to adding line breaks and spaces, so you can structure your code to make it more clear and understandable."

12. What is the use of confirm() function in JavaScript?

The confirm() function in JavaScript is used to show a pop-up dialog box that asks the user to confirm or cancel an action. It's often used to get the user's consent before proceeding with a certain operation, like deleting a file or submitting a form.

13. What is the purpose of prompt() function in JavaScript?

prompt() are used to take input from user. in prompt we pass one message that message show in prompt popup.

14. What is an operator and what are their types in Javascript?

Operators are used to perform certain operations on one or more values or variables.

Some common types of operators :

  1. Arithmetic operators (+, -, *, /).
  2. Assignment operators (=, +=, -=, *=, /=)
  3. Increment & Decrement operators
  4. Comparison operators (<, >, <=, >=, ==, !=)
  5. Logical operators (&& (logical AND), || (logical OR), ! (logical NOT))

15. What is a ternary operator?

The ternary operator, also known as the conditional operator, It's easy way to write simple conditional expressions. It provides a concise way to evaluate a condition and return one of two values based on whether the condition is true or false.

Syntax :

condition ? expressionIfTrue : expressionIfFalse;

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

The difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.

17. Explain the conditional statments in JavaScript.

1. The if/else statement is a JavaScript conditional statement that executes a block of code if a specified condition is true, and if the condition is false, another block of code can be executed.
2. This statement is part of JavaScript's "Conditional" Statements, which are used to perform different actions based on different conditions

18. How do you take input from users in JavaScript?

To take input from users in JavaScript, you can use the prompt() function.
For Ex.

let input = prompt("Please enter something:");
console.log("User entered: " + input);

19. What happens if you forget to include a break statement in a switch case?

If you forget to include a break statement in a switch case in JavaScript, the code will continue to execute subsequent case statements .

let fruit = "apple";
switch (fruit) {
case "apple":
console.log("It's an apple.");
// No break statement
case "banana":
console.log("It's a banana.");
break;
case "cherry":
console.log("It's a cherry.");
break;
default:
console.log("It's something else.");
break;
}

Output : It's an apple.
It's a banana.

In above example notice that after the first matching case ("apple"), it continues to execute the code in the next case ("banana") because there is no break statement between them. It only stops when it encounters a break statement or reaches the end of the switch statement.

20. Explain the document.write() function.

1. document: This is a built-in object in JavaScript that represents the web page/document.
2. write(): This is a method of the document object. It allows you to write content directly to the HTML document.

21. Explain if-else statement in JavaScript.

In the if-else statement executes one block of code if the condition is true and a different block if the condition is false.

22. What is the syntax of a switch statement in JavaScript?

Syntax

switch (expression) {
case value1:
// Code to be executed if expression matches value1
break;
case value2:
// Code to be executed if expression matches value2
break;
case value3:
// Code to be executed if expression matches value3
break;
default:
// Code to be executed if expression doesn't match any of the values
break;
}

23. What are the different data types in JavaScript?

### 1. String

A string is a data type used to represent textual data. It consists of a sequence of characters enclosed within single ('') or double ("") quotation marks.

Example :

"Hello, I'm a string"

'Hello, How are you...'

2. Int​

Integers are whole numbers without decimal points.

Example :

123456

3. Float​

Floats are numbers with decimal points.

8793.90

4. Boolean​

A boolean represents one of two possible values: true or false.

true or false

24. What is the difference between null and undefined in JavaScript?

1. undefined:

undefined represents a variable that has been declared but has not been assigned any value yet. It is also the default value of function parameters that are not provided when a function is called.

let x;
console.log(x); // undefined
function greet(name) {
console.log("Hello, " + name);
}
greet(); // Hello, undefined
  1. null

null is a deliberate assignment to a variable or property indicating the absence of any object value. It represents an intentional absence of any object value or a "no value" value.

let y = null;
console.log(y); // null

25.What is a string in JavaScript??

In JavaScript, a string is a data type used to represent a sequence of characters, such as text. Strings are one of the fundamental data types in JavaScript, and they are used extensively for working with textual data.

26.What are the pop-up boxes in JavaScript?

In JavaScript, pop-up boxes are dialog boxes or windows that are displayed on the user's screen to interact with them or provide information.

27. Can you explain what a switch statement is and how it is used in JavaScript?

A switch statement is a control structure in JavaScript (and many other programming languages) that allows you to evaluate a variable or expression against multiple possible case values. It provides a way to execute different blocks of code based on the value of the variable or expression.

Here's how a switch statement works :

1. The expression is evaluated, and its value is compared to each case value sequentially.

  1. If a case value matches the expression, the code block associated with that case is executed. The break statement is used to exit the switch statement after executing the code for the matched case.

  2. If none of the case values match the expression, the code block under the default label (if present) is executed. The default case is optional, and it serves as a fallback when no other cases match.

28. What is function in JavaScript? Explain its types.

A function in JavaScript is a block of code that performs a specific task and can be called or executed multiple times.

Function code block which can be reused to perform a specific task.

1. Inbuilt​

In JavaScript, inbuilt functions already have predefined meanings for various tasks. This means that the meaning is already defined and known to JavaScript.

Example :

alert() : An alert box will be displayed that contains a message along with an OK button.
prompt() :A prompt box displays an additional input field for the user to provide a value for output.
console.log() : You can use the browser console to display messages or values.
parseInt() : Converts a string into an Integer.
parseFloat() : Converts a string into a Floating-point number.

2. User Define​

By using the function keyword, to create and define your own functions known as user-defined functions.
Syntax :

function <function-name> ()
{
// Block of Code
}

29. What is an arrow function in JavaScript?

Arrow functions are a shorter way to write functions in JavaScript. They are especially handy for small, simple functions.
syntax :
```js const variableName = (paameters) => ; ```

30. How do you pass arguments to a function?

In JavaScript, you can pass arguments to a function when you call it. Arguments are values or expressions that you provide to the function, and the function can use these arguments to perform some actions or calculations.

31. What is the use of parseInt() function?

The parseInt() function is a JavaScript function that is used to parse a string and convert it into an integer.

32. What is break and continue statments in JavaScript?

In JavaScript, break and continue are control flow statements that are used in loops to alter the flow of execution.

1. break
The break statement is used to exit (or "break out of") a loop prematurely. It is typically used within for, while, or do...while loops to terminate the loop's execution.
When break is encountered, the loop in which it resides is immediately terminated, and program control moves to the first statement after the loop.

2. continue
The continue statement is used to skip the current iteration of a loop and move to the next iteration.
It is often used when a certain condition is met, and you want to skip the current iteration but continue with the rest of the loop.

33. What is the difference between an alert() and a confirmation()?

1. alert() Function:
The alert() function is used to display a simple dialog box with a message to the user. It's typically used to show a message or information to the user.

2. confirm() Function:
The confirm() function is used to display a dialog box with a message and two buttons: "OK" and "Cancel." It's typically used to ask the user for a yes/no or OK/cancel decision.

34. What is the use of getElementById() method in JavaScript?

In JavaScript used to access and manipulate elements in a web pages Document Object Model (DOM). It allows you to select an HTML element by its unique id attribute, which should be assigned to the element in the HTML markup.

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

The return statement causes the function to stop executing and to return the value of its expression .

36. What is the difference between function declarations and function expressions?

1. Function Declaration
To declare a function, you use the function keyword and specify a name for the function.

2. Function Expression
Here, you create a function expression and assign it to a variable that can be called.

37. What are the rules for naming variables in JavaScript?

Rules to declare variables:

1. Use letters a-z, A-Z, digits 0-9, and underscore _.
2. Variables cannot start with numbers.
3. Variable names cannot be reserved keywords.
4. Variable names are case-sensitive, which means name and Name are considered different variables.

38. What are the primitive dataype in JavaScript?

1. String
A string is a data type used to represent textual data. It consists of a sequence of characters enclosed within single ('') or double ("") quotation marks.

2 . Int
Integers are whole numbers without decimal points.

3. Float
Floats are numbers with decimal points.

4. Boolean
A boolean represents one of two possible values: true or false.

39. How do you concatenate strings in JavaScript?

You can use the + operator to concatenate strings together. When the + operator is used with strings, it joins them together.

40. What are the basic arithmetic operators in JavaScript?

Arithmetic operators for performing mathematical operations on numeric values.

1. Addition (+): Used to add two or more numbers or concatenate strings.
2. Subtraction (-): Used to subtract one number from another.
3. Multiplication (*): Used to multiply two numbers.
4. Division (/): Used to divide one number by another.
5. Modulus (%): Used to find the remainder of the division of one number by another.

41. What is the difference between a parameter and an argument in JavaScript functions?

1. Parameter:

A parameter is a variable or a named placeholder in the function definition. It's a part of the function's signature, and it serves as a way to receive input data when the function is called. Parameters are defined in the function declaration and are enclosed in parentheses. They act as local variables within the function and represent the values that the function expects to receive when it's called.

2. Argument:

An argument is an actual value or expression that you pass to a function when you call it. These values are provided within the parentheses when invoking the function. Arguments are the data you supply to the function for the parameters to use.

42. How do you return a value from a JavaScript function?

In JavaScript, you can return a value from a function using the return statement. The return statement is followed by an expression or a value that you want to pass back as the result of the function.

43. How do you select an element by its ID in JavaScript?

In JavaScript, you can select an HTML element by its ID using the getElementById method, which is a part of the Document Object Model (DOM).

 ```html
<!DOCTYPE html>
<html>
<head>
<title>document</title>
</head>
<body>
<div id="mydiv">
<p>This is div with ID.</p>
</div>

<script>
var myElement = document.getElementById("mydiv");


myElement.style.backgroundColor = "lightblue";
myElement.innerHTML = "Content changed using JavaScript";
</script>
</body>
</html>

```

44. What is the difference between getElementById() and getElementsByClassName()?

1. getElementById():

This method is used to select a single HTML element with a specific id attribute. Since id attributes must be unique on a page, getElementById() returns only one element .

2. getElementsByClassName():

This method is used to select multiple HTML elements that pass the same class attribute.

45. How can you select multiple elements with the same class name in JavaScript?

getElementsByClassName():

The getElementsByClassName() method returns a live HTMLCollection of elements with the specified class name. You can access the elements by their index within the collection.

46. How can you add a CSS class to an element using JavaScript?
Get a reference to the HTML element that you want to add a class to. You can do this by selecting the element using JavaScript,
for example :
by using document.getElementById, document.querySelector, or any other method that suits your needs.

Use the classList property to add the CSS class to the element. The classList property has several methods for manipulating classes, with add being used to add a class.

47. What are the different methods available in JavaScript for selecting elements from the DOM?

getElementById – search element by element_id
getElementsByTagName – search element by tag name (e.g., span, div)
getElementsByClassName – search element by class name

48. How does the querySelector method differ from querySelectorAll when selecting elements?

The querySelector and querySelectorAll methods are used for selecting elements in the Document Object Model (DOM) in JavaScript, but they differ in terms of the number of elements they select and return.

1.querySelector:
Selects a single element: querySelector is used to select the first element that matches the specified CSS selector. Returns a single element: It returns the first matched element or null if no element matches the selector.

2. querySelectorAll: Selects multiple elements: querySelectorAll is used to select all elements that match the specified CSS selector. Returns a NodeList: It returns a NodeList, which is a collection of elements, even if there's only one match. You can iterate through the NodeList using methods like forEach or by index to access individual elements.

49. How do you select all elements with a specific class using JavaScript?

To select all elements with a specific class using JavaScript, you can use the document.querySelectorAll method.

50. What is loop in Javascript?

In JavaScript, a loop is a control structure that allows you to repeatedly execute a block of code. Loops are essential for performing tasks like iterating over arrays, processing lists of data, and executing code multiple times until a certain condition is met.

51. What are the different types of loops available in JavaScript?

In JavaScript, there are several types of loops that are commonly used for iterating over data or executing a block of code repeatedly.

1. for loop:
A standard loop that repeats until a specified condition evaluates to false. This loop is often used when the number of iterations is known.

2. while loop:
This loop repeats as long as a specified condition evaluates to true. It is commonly used when the number of iterations is not known beforehand.

3. do-while loop:
Similar to the while loop, but the code block is executed at least once before the condition is checked.

52. What is the purpose of break keyword and continue keyword?

The break and continue keywords are used within loops to control the flow of the loop execution.

1. Break : The break statement is used to immediately terminate a loop. When the break statement is encountered inside a loop.

2. continue: The continue statement is used to skip the current iteration of a loop and continue with the next iteration.

53. What is the difference between while and do-while loop?

1. while loop:
In a while loop, the condition is evaluated before the execution of the loop's body. If the condition is false initially, the loop's body will never be executed.

2. Do-While:
In a do-while loop, the condition is evaluated after the execution of the loop's body. This guarantees that the loop's body will execute at least once, even if the condition is initially false.

54. What is loop? What are the different types of loops available in JavaScript?

In JavaScript, there are several types of loops that are commonly used for iterating over data or executing a block of code repeatedly.

1. for loop:
A standard loop that repeats until a specified condition evaluates to false. This loop is often used when the number of iterations is known.

2. while loop:
This loop repeats as long as a specified condition evaluates to true. It is commonly used when the number of iterations is not known beforehand.

3. do-while loop:
Similar to the while loop, but the code block is executed at least once before the condition is checked.

55. What is array in Javascript and how to define array?

In JavaScript, an array is a special variable that is used to store multiple values in a single variable.

let arr = [1, 2, 3, 4, 5];

56. Which methods are present in an array ?

1. push()
2. pop()
3. unshift()
4. shift()
5. splice()
6. length
7. join()
8. sort
9. indexOf()
10. reverse()

57. What is the purpose of length in an array ?

To count total elements in the array.

let marks = [50, 45, 30, 20, 10];
marks.length;

output: 5;

58. Why we used push() method in an array?

To add element from the end of array.

59. Could you explain used of pop() method in an array?

To remove element from the end of array.

60. What is the difference between unshift() and shift() method in an array?

1. unshift() :
To insert element from the start of array.

2. shift() :
To delete elements from the start of array.

61. How can I perform both insertion and deletion of elements in an array simultaneously? Which methods should I use for these operations?

splice() method in JavaScript is used to change the contents of an array by removing or replacing existing elements and adding new elements in place .

62. How do you search for a specific element in an array?

The indexOf() method returns the first index at which a given element can be found in the array.

63. How do you insert an element at a specific position in an array?

To insert an element at a specific position in a JavaScript array, you can use the splice() method. The splice() method allows you to add or remove elements from an array while specifying the position where you want to insert the new element.

64. How do you insert an element at the end of an array?

you can use the push() method to insert an element at the end of an array.

65. What is the difference between a static array and a dynamic array?

1. Dynamic Array in JavaScript:

In JavaScript, arrays are dynamic in nature, meaning they can change in size dynamically during runtime.

2. Static Array in JavaScript:

The term "static array" in the context of JavaScript usually refers to arrays that have a fixed size defined at the time of their declaration.

66. Explain the concept of an array and its advantages in programming.

An array is a fundamental data structure used for storing and organizing a collection of elements of the same data type. It provides a way to access and manipulate a group of items sequentially using an index.

67. How do you sort an array in ascending order which method we can use?

In JavaScript, you can sort an array in ascending order using the sort() method.

68. How do you reverse the elements of an array?

To reverse the elements of an array in JavaScript, you can use the reverse() method.

69. How do you handle asynchronous operations in JavaScript?

1. Callbacks: You can use callbacks to handle asynchronous operations. Callbacks are functions that are passed as arguments to other functions and are executed when the asynchronous operation is completed. However, nested callbacks can lead to callback hell, making the code difficult to read and maintain.

2. Promises: Promises provide a cleaner way to handle asynchronous operations. They represent a value that might be available now, or in the future, or never. Promises have a chainable syntax that allows you to attach callbacks for successful or failed completion of an asynchronous operation. They help avoid callback hell and make asynchronous code more readable.

3. Async/await: Async/await is a modern syntax for handling asynchronous operations in JavaScript. Async functions enable you to write asynchronous code as if it were synchronous. The async keyword is used to define an asynchronous function, and the await keyword is used to pause the execution of the function until a promise is settled.

70. What is the fullform of JSON?

The full form of JSON is "JavaScript Object Notation".

71. What is an object in JavaScript?

In JavaScript, an object is a standalone entity, with properties and type. It is similar to real-life objects, which possess properties and behaviors. An object can be created with curly braces and can have properties and methods.

72. What is the purpose of JSON in JavaScript?

In JavaScript, JSON serves the purpose of facilitating data exchange between a server and a web application.

73. How to store element in JSON object?

To store elements in a JSON object in JavaScript, you typically define key-value pairs within curly braces .

74. How do you convert a JavaScript object to a JSON string?

In JavaScript, you can convert a JavaScript object to a JSON string using the JSON.stringify() method

75. How do you add an element to an array in JavaScript?

To add an element to array in JavaScript, you can use push(), unshift() method.

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

1. forEach
In JavaScript, the forEach() method is used to execute a provided function once for each array element. It is similar to a for loop but provides a more concise and readable way to iterate over elements in an array.

2. Map
In JavaScript, the map() method is used to create a new array by applying a function to each element of the original array. It does not change the original array, but it returns a new array with the results of applying the provided function to each element.

77. What is the purpose of the this keyword in JavaScript?

In JavaScript, the this keyword refers to the object that is executing the current function. It is a fundamental concept in JavaScript and is used to access the current object's properties and methods within a function.

78. How do you handle errors and exceptions in JavaScript?

In JavaScript, you can handle errors and exceptions using try...catch blocks and the throw statement. This mechanism allows you to control the flow of your program when an error occurs, preventing the script from crashing. Here's how you can use try...catch blocks to handle errors.

79. What is event in JavaScript?

event is an action that occurs as a result of user interaction with the web page or the browser. This interaction can include mouse clicks, keyboard actions, or other actions such as the page loading or unloading. Events can be used to trigger functions or scripts that respond to user actions or system events.

80. How do you handle onclick and onmouseover event in JavaScript?

you can handle the onclick and onmouseover events using event handlers or by assigning functions directly to the events.

81. What are the different types of events available in JavaScript?

1. onclick: The onclick event in Javascript occurs when the user clicks on an element.
2. onchange: The onchange event in JavaScript is triggered when the value of an element or form element is changed by the user.
3. onkeypress : The onkeypress event is triggered when a user presses a key on the keyboard.
4. onkeydown: The onkeydown event is activated when a key on the keyboard is pressed down.
5. onkeyup : The keyup event is triggered when a key on the keyboard is released after being pressed.
6. onmouseover: The onmouseover event occurs when the pointer is moved onto an element.
7. onmouseout: The onmouseoutevent in JavaScript is triggered when the mouse pointer moves out of an element.
8. onmousemove: The onmousemove event is triggered when the mouse pointer moves over an HTML element and generates a continuous stream of events as the mouse moves.
9. ondblclick: The ondblclick event is triggered when a user double-clicks on an HTML element.
10. onload: When the webpage loads, the onload event is triggered.

82. How do you handle keyboard events in JavaScript?

The onload event is triggered when a webpage and all its resources have finished loading, including images, scripts, and stylesheets.

83. How do you stop event propagation?

To stop event propagation in JavaScript, you can use the stopPropagation() method on the event object. This prevents the event from bubbling up the DOM hierarchy, ensuring that it does not trigger any additional event listeners attached to parent elements.

84. What is the difference between onkeypress and onkeyup event?

1. onkeypress:

The onkeypress event is triggered when a key is pressed down and that key normally produces a character value. It is primarily used for listening to printable characters such as letters or numbers.

2. onkeyup:
The onkeyup event is triggered when a key is released after being pressed. It occurs after the onkeypress event and provides information about the key that was released.

85. What is an object in JavaScript, and how is it different from other data types?

Objects in JavaScript can be compared to real-life objects. They have properties that define their characteristics. These properties can be primitive data types, other objects, or functions.

86. What is the difference between dot notation and bracket notation when accessing object properties?

1. Dot Notation:
Dot notation is used when the property name is known and is a valid identifier meaning it doesn't contain special characters or spaces. It is more concise and easier to read, which makes it preferable when the property name is static and known in advance.

2. Bracket Notation:
Bracket notation is used when the property name is dynamic, i.e., when it is stored in a variable or when it's a string that might not be a valid identifier. It allows for the use of expressions to dynamically compute the property name at runtime.

87. How do you select an element by its ID in JavaScript?

you can select an HTML element by its ID using the getElementById method.

88. How do you select elements by their class name in JavaScript?

you can use the getElementsByClassName method.

89. How do you select elements by their tag name in JavaScript?

you can use the getElementsByTagName method.

90. What is the difference between for and while loops in JavaScript?

1. for:
The for loop is the most commonly used loop in JavaScript. It iterates over a block of code a specific number of times.

2. while:
In a while loop, the loop executes as long as the condition is true.

91. What is an infinite loop, and how do you avoid it in JavaScript?

An infinite loop is a loop that runs indefinitely because its exit condition is never met or there is no exit condition specified.

92. How do you skip the current iteration and move to the next one in a loop?

you can use the continue statement to skip the current iteration and continue with the next iteration in a loop. This statement is typically used within loops, such as for loops, while loops, or do-while loops. When the continue statement is encountered, the remaining code within the loop for the current iteration is skipped, and the loop proceeds with the next iteration.

93. How does the for loop work in JavaScript?

1. Initialization: Typically used to initialize the loop counter. It is executed only once before the loop starts.
2. Condition: The condition is evaluated before each iteration. If it evaluates to true, the loop continues. If it evaluates to false, the loop ends.
3. Inc/Dec: Executed at the end of each iteration. It can be used to update the loop counter or perform any other necessary actions.

94. How does the while loop work in JavaScript?

It keeps iterating as long as the condition evaluates to true. Once the condition becomes false, the loop

95. How does the do-while loop work in JavaScript?

It has a similar purpose of executing a block of code repeatedly as long as a specified condition is true. The key difference is that in a do-while loop, the condition is evaluated after the execution of the loop's body. This guarantees that the loop body is executed at least once, even if the condition is initially false.

96. How do you break out of a loop in JavaScript?

you can use the break statement to immediately terminate a loop. When the break statement is encountered inside a loop, the loop stops its execution, and the program control moves to the statement immediately following the loop.

The break statement can be used with various types of loops such as for, while, and do-while loops. It is commonly used in conjunction with an if statement to terminate the loop when a certain condition is met.

97. What is an parseFloat() function in JavaScript?

The parseFloat() function in JavaScript is used to parse a string and return a floating-point number.

98. What are excape characters?

Escape characters are characters in a string that are used to perform specific tasks.

99. What is the splice() method in JavaScript?

This function can perform insertion and deletion at once.
Syntax :

splice(index, no.of elements to delete, elements to insert)

100. What is the use of the indexOf() method?

indexOf() method is used to find an array of element.