QUIZ 100 Questions LEARN JAVASCRIPT Elevate Your JavaScript Knowledge with Our Ultimate Quiz

QUIZ 100 Questions LEARN JAVASCRIPT 🌐 Elevate Your JavaScript Knowledge with Our Ultimate Quiz! 🚀🧠

Introduction to the quiz

Are you ready to test your knowledge and dive deep into the intricacies of JavaScript? We’ve crafted an engaging quiz that challenges your understanding of this versatile language. No code – just pure logic and fun! 🎉

🔍 Challenge Yourself with These Questions:

  • What’s the right way to link an external JavaScript file named “script.js”?
  • Can you define the correct syntax for writing an array in JavaScript?
  • Ever wondered what the finally block does in a try…catch statement?
  • Do you know which operator checks both the value and type for equality?
  • Think about it: what will console.log(0.1 + 0.2 == 0.3) output?

But wait, there’s more! 🌟

  • Dive into conditional statements, loop creations, and array manipulations.
  • Unravel the mysteries of this keyword, data types, and object creation.
  • Discover the nuances of asynchronous operations and event handling in JavaScript.

👨‍💻 Why Take This Quiz?

  • Sharpen your JavaScript skills and concepts.
  • Identify areas to focus on in your learning journey.
  • Stay updated with essential JavaScript functionalities.
  • Connect with fellow developers and share your insights.

🤔 Whether you’re a pro at writing functions or still figuring out array methods, this quiz is an exciting way to assess and expand your coding arsenal.

💬 Share your thoughts, scores, or any intriguing JavaScript facts you’ve encountered in your developer journey! Let’s create a wave of learning and inspiration across our tech community!

#JavaScript #CodingQuiz #WebDevelopment #ProgrammingChallenge #TechCommunity #LearnToCode #FrontEndDevelopment #JavaScriptTrivia #CodingLife #WebDev #TechSkills #DigitalLearning #CodingChallenges #CodeNewbie #DevCommunity #JavaScriptQuestions #TechTalks #CodingIsFun #JavaScriptDeveloper

Questions about JavaScript

1. What is the correct syntax for referring to an external script called “script.js”?

A. <script href=”script.js”>

B. <script name=”script.js”>

C. <script src=”script.js”>

D. <script file=”script.js”>

Answer: C

2. How do you write a comment in JavaScript?

A. <!–This is a comment–>

B. //This is a comment

C. /* This is a comment */

D. Both B and C

Answer: D

3. How do you declare a JavaScript variable?

A. var name = ‘value’;

B. v name = ‘value’;

C. value var name;

D. variable name = ‘value’;

Answer: A

4. Which method is used to round a number to the nearest integer?

A. Math.round()

B. Math.ceil()

C. Math.floor()

D. Math.random()

Answer: A

5. How do you create a function in JavaScript?

A. function: myFunction()

B. function = myFunction()

C. function myFunction()

D. function => myFunction()

Answer: C

6. Which event is triggered when a user clicks on an HTML element?

A. onmouseover

B. onchange

C. onclick

D. onfocus

Answer: C

7. How can you convert a string to an integer in JavaScript?

A. int.parse()

B. Math.int()

C. parseInt()

D. Number.parse()

Answer: C

8. How do you find the element with an ID of “demo”?

A. document.getElement(‘demo’)

B. document.getElementById(‘demo’)

C. document.querySelector(‘#demo’)

D. Both B and C

Answer: D

9. What will this code return? Boolean(10 > 9)

A. true

B. false

C. NaN

D. undefined

Answer: A

10. What is the correct way to write an array in JavaScript?

A. var colors = (1:”red”, 2:”green”, 3:”blue”)

B. var colors = 1 = (“red”), 2 = (“green”), 3 = (“blue”)

C. var colors = “red”, “green”, “blue”

D. var colors = [“red”, “green”, “blue”]

Answer: D

11. Which operator is used to check both the value and the type?

A. ==

B. ===

C. =

D. !=

Answer: B

12. What will console.log(0.1 + 0.2 == 0.3) output?

A. true

B. false

C. NaN

D. undefined

Answer: B

13. How to write an if statement in JavaScript?

A. if i = 5 then

B. if i == 5

C. if (i == 5)

D. if i = 5

Answer: C

14. Which method converts JSON data to a JavaScript object?

A. JSON.parse()

B. JSON.stringify()

C. JSON.toObject()

D. JSON.toArray()

Answer: A

15. How do you start a for loop?

A. for (i <= 5; i++)

B. for (i = 0; i <= 5)

C. for (i = 0; i <= 5; i++)

D. for i = 1 to 5

Answer: C

16. What method is used to add new items to the end of an array?

A. push()

B. pop()

C. concat()

D. join()

Answer: A

17. How do you declare a JavaScript variable that cannot be re-assigned?

A. let

B. var

C. const

D. immutable

Answer: C

18. How can you add a comment in JavaScript?

A. <!–This is a comment–>

B. //This is a comment

C. /* This is a comment */

D. Both B and C

Answer: D

19. What will be the output of console.log(typeof “Hello”)?

A. string

B. text

C. Object

D. char

Answer: A

20. Which of these is a way to handle asynchronous operations in JavaScript?

A. for..of

B. Promises

C. Array.forEach()

D. JSON.parse()

Answer: B

21. What is used in JavaScript for conditional execution of statements?

A. switch

B. for

C. while

D. do-while

Answer: A

22. How do you stop the execution of a loop?

A. stop()

B. exit()

C. break

D. halt()

Answer: C

23. Which method can be used to combine two arrays?

A. Array1.concat(Array2)

B. Array1.append(Array2)

C. Array1.join(Array2)

D. Array1.merge(Array2)

Answer: A

24. How do you select elements with the class name “example” in JavaScript?

A. document.getElement(‘example’)

B. document.getElementsByClassName(‘example’)

C. document.querySelector(‘.example’)

D. Both B and C

Answer: D

25. What does the this keyword refer to in a JavaScript function?

A. The document object

B. The function itself

C. The object that called the function

D. The window object

Answer: C

26. Which of the following is NOT a JavaScript data type?

A. String

B. Number

C. Boolean

D. Float

Answer: D

27. How do you create a new Date object in JavaScript?

A. new Date()

B. Date.new()

C. Date()

D. new Date.now()

Answer: A

28. What method is used to send a request to a web server and load data without reloading the page?

A. XMLHttpRequest()

B. fetch()

C. Both A and B

D. loadData()

Answer: C

29. How do you check if a variable is an array in JavaScript?

A. Array.isArray(variable)

B. variable.isArray()

C. variable.typeof() == ‘array’

D. typeof variable == ‘array’

Answer: A

30. What is the purpose of the addEventListener method in JavaScript?

A. To create a new HTML element

B. To write HTML content to a document

C. To listen for a specified event type on an element

D. To add a new attribute to an HTML element

Answer: C

31. Which of the following is a way to define an anonymous function?

A. function() {}

B. () => {}

C. Both A and B

D. function anonymous() {}

Answer: C

32. Which JavaScript method is used to access an HTML element by its ID?

A. document.getElement()

B. document.getElementById()

C. document.querySelector()

D. Both B and C

Answer: D

33. How do you write a loop in JavaScript that repeats 5 times?

A. for (i = 0; i < 5; i++) {}

B. for (i = 1; i <= 5; i++) {}

C. Both A and B

D. while (i < 5) {}

Answer: C

34. What is the output of console.log(1 + “2” + “2”)?

A. “5”

B. “122”

C. “32”

D. 5

Answer: B

35. How do you create an object in JavaScript?

A. var person = {name: “John”, age: 30};

B. var person = new Object(name: “John”, age: 30);

C. var person = Object.create(“John”, 30);

D. var person = {“name”: “John”, “age”: 30};

Answer: A

36. Which method can be used to remove the last element from an array and return that element?

A. pop()

B. push()

C. shift()

D. unshift()

Answer: A

37. In JavaScript, what is a closure?

A. A function combined with its lexical environment

B. An error that occurs due to undefined variables

C. A feature used for data hiding and encapsulation

D. The process of linking a child function to a parent function

Answer: A

38. What does NaN stand for in JavaScript?

A. Not a Name

B. Not a Number

C. New and Noteworthy

D. None of the Above

Answer: B

39. What is the result of “10” == 10 in JavaScript?

A. true

B. false

C. TypeError

D. NaN

Answer: A

40. Which method is used to serialize an object into a JSON string in JavaScript?

A. JSON.parse()

B. JSON.stringify()

C. JSON.serialize()

D. JSON.toString()

Answer: B

41. What method is used to add one or more elements to the beginning of an array?

A. unshift()

B. shift()

C. push()

D. pop()

Answer: A

42. Which statement correctly stores data in the browser’s local storage?

A. localStorage.saveItem(‘key’, ‘value’);

B. localStorage.setItem(‘key’, ‘value’);

C. localStorage.store(‘key’, ‘value’);

D. localStorage.newItem(‘key’, ‘value’);

Answer: B

43. How do you declare a constant in JavaScript?

A. let CONST_NAME;

B. const CONST_NAME;

C. constant CONST_NAME;

D. var CONST_NAME;

Answer: B

44. Which of these methods can be used to delay the execution of a function in JavaScript?

A. setTimeout()

B. delay()

C. wait()

D. pause()

Answer: A

45. How do you find the length of a string in JavaScript?

A. string.length

B. string.size()

C. length(string)

D. sizeOf(string)

Answer: A

46. Which of the following is true about the this keyword in JavaScript?

A. It always refers to the global object.

B. It refers to the object from where it was called.

C. It refers to the function in which it is used.

D. It is a constant.

Answer: B

47. What will the following code return: console.log(typeof [1,2,3])?

A. “array”

B. “object”

C. “number”

D. “list”

Answer: B

48. Which method is used to sort the elements of an array?

A. sort()

B. order()

C. arrange()

D. lineup()

Answer: A

49. What is the correct syntax for creating a promise in JavaScript?

A. new Promise()

B. Promise()

C. Promise.new()

D. new Promise(function(resolve, reject) {})

Answer: D

50. What will the following statement return? Boolean(null)

A. true

B. false

C. null

D. TypeError

Answer: B

51. How can you check if a variable x is an instance of a class Y?

A. x instanceof Y

B. Y.instance(x)

C. x.isInstance(Y)

D. instance(x).of(Y)

Answer: A

52. Which is the correct JavaScript operator for strict inequality (not equal value or not equal type)?

A. !=

B. !==

C. <>

D. ~=

Answer: B

53. How can you get the total number of arguments passed to a function?

A. Using args.length

B. Using arguments.length

C. Using this.arguments

D. Using function.length

Answer: B

54. How can you convert the string “123” into a number?

A. Number(“123”)

B. parseInt(“123”)

C. Both A and B

D. toString(“123”)

Answer: C

55. What is the purpose of the Array.map() method?

A. It calls a function for each element in the array.

B. It creates a new array with the results of calling a provided function on every element.

C. It executes a function on every element in the array, without creating a new array.

D. It merges two or more arrays.

Answer: B

56. What does the document.querySelector() method return?

A. The first element within the document that matches the specified group of selectors.

B. All elements within the document that match the specified group of selectors.

C. The last element within the document that matches the specified group of selectors.

D. An array of all elements that match the specified group of selectors.

Answer: A

57. In JavaScript, which of these is used for deep copying an object?

A. Object.assign()

B. JSON.parse(JSON.stringify(object))

C. Object.copy()

D. object.deepCopy()

Answer: B

58. What will be the output of console.log(“Hello” || “World”)?

A. “Hello”

B. “World”

C. “HelloWorld”

D. undefined

Answer: A

59. Which method is used to remove the first element from an array and return that element?

A. pop()

B. shift()

C. unshift()

D. push()

Answer: B

60. What is the output of console.log(1 + “2” + 3)?

A. “6”

B. “123”

C. “15”

D. “33”

Answer: B

61. What is the correct syntax for a JavaScript arrow function?

A. var myFunction = () => {};

B. var myFunction() => {};

C. function myFunction => {};

D. var myFunction = function() {};

Answer: A

62. What does the Array.filter() method do?

A. Filters the array for elements that do not meet the condition.

B. Creates a new array with all elements that pass the test implemented by the provided function.

C. Changes all elements in an array based on a test function.

D. Sorts the array based on a filter condition.

Answer: B

63. Which method is used to combine the strings of two or more strings in JavaScript?

A. concat()

B. append()

C. attach()

D. add()

Answer: A

64. What does the forEach() method do in JavaScript?

A. Executes a provided function once for each array element and returns a new array.

B. Executes a provided function once for each array element without modifying the array.

C. Loops through an array and executes a function for each element, returning undefined.

D. Filters elements in an array and applies a function to each element.

Answer: C

65. What is Event Propagation in JavaScript?

A. The process of error handling in event listeners.

B. The concept of adjusting event listeners in the DOM.

C. The way events propagate through the DOM tree.

D. The method of creating custom events.

Answer: C

66. In JavaScript, how is a try…catch block used?

A. To handle potential errors in a block of code.

B. To repeat a block of code a specified number of times.

C. To define a new scope for variables.

D. To test the speed of a block of code.

Answer: A

67. Which JavaScript method is used for rounding a number down to its nearest integer?

A. Math.floor()

B. Math.ceil()

C. Math.round()

D. Math.trunc()

Answer: A

68. What does the map() method return in JavaScript?

A. A new array with the results of the calling function for each element.

B. The first element that satisfies the provided testing function.

C. An updated version of the original array.

D. undefined.

Answer: A

69. What will the following code return? console.log(“10” === 10)

A. true

B. false

C. TypeError

D. NaN

Answer: B

70. Which of these values is considered falsy in JavaScript?

A. 0

B. “0”

C. {}

D. []

Answer: A

71. How do you declare a Read-Only property in a JavaScript object?

A. Using the const keyword.

B. With Object.freeze().

C. By setting the property’s writable attribute to false.

D. It’s not possible in JavaScript.

Answer: C

72. What is the purpose of the bind() method in JavaScript?

A. To bind an object to a function.

B. To permanently bind a function to its current context.

C. To combine two strings.

D. To bind two arrays together.

Answer: B

73. How do you find the type of a variable in JavaScript?

A. typeof(variable)

B. variable.type()

C. Type(variable)

D. variable.getType()

Answer: A

74. What is the output of console.log(“1” – – “1”)?

A. “11”

B. 2

C. NaN

D. “2”

Answer: B

75. Which method is used to join two or more strings in JavaScript?

A. string.join()

B. string.concat()

C. string.merge()

D. string.combine()

Answer: B

76. How do you select all paragraph elements in a document?

A. document.getElement(‘p’)

B. document.querySelector(‘p’)

C. document.querySelectorAll(‘p’)

D. document.getElements(‘p’)

Answer: C

77. What is the default behavior of a <form> element’s submit action in HTML?

A. To clear the form

B. To save the form data

C. To send the form data to a server

D. To validate form data

Answer: C

78. What is the method to parse a JSON string into a JavaScript object?

A. JSON.parse()

B. JSON.stringify()

C. JSON.toObject()

D. JSON.toJS()

Answer: A

79. How do you declare a JavaScript variable that can change in value?

A. var

B. let

C. const

D. Both A and B

Answer: D

80. What will console.log(typeof null) return?

A. “null”

B. “object”

C. “undefined”

D. “NaN”

Answer: B

81. What is the result of console.log(“2” + 3 + 5)?

A. 10

B. “235”

C. “10”

D. “25”

Answer: B

82. Which method can be used to find the first element that satisfies a provided test function in an array?

A. find()

B. filter()

C. map()

D. forEach()

Answer: A

83. In JavaScript, how do you get the current date and time?

A. new Date()

B. Date.now()

C. getCurrentDate()

D. Both A and B

Answer: D

84. What is the purpose of the splice() method in an array?

A. To search for specific elements.

B. To add/remove elements from an array.

C. To split an array into chunks.

D. To replace the contents of an array.

Answer: B

85. What keyword is used to define a variable that can be reassigned in JavaScript?

A. var

B. let

C. const

D. Both A and B

Answer: D

86. Which of the following methods can be used to convert an array into a string?

A. toString()

B. join()

C. Both A and B

D. stringify()

Answer: C

87. What is the correct syntax to create an anonymous function in JavaScript?

A. function() {}

B. var func = function() {};

C. () => {};

D. Both B and C

Answer: D

88. How do you check if an object myObj is an array in JavaScript?

A. myObj.isArray()

B. Array.isArray(myObj)

C. myObj.type() === “array”

D. typeof myObj === “array”

Answer: B

89. What will the following code return? Boolean(“false”)

A. true

B. false

C. TypeError

D. undefined

Answer: A

90. How do you find the character at a specific index in a string in JavaScript?

A. charAt(index)

B. charCodeAt(index)

C. indexOf(index)

D. getChar(index)

Answer: A

91. Which of these is a correct method to create a new object in JavaScript?

A. var obj = {};

B. var obj = new Object();

C. var obj = Object.create(null);

D. All of the above

Answer: D

92. What is the result of “Hello”.substring(1, 3)?

A. “el”

B. “ell”

C. “hel”

D. “ello”

Answer: A

93. What will be the output of console.log(0.1 + 0.2 === 0.3)?

A. true

B. false

C. SyntaxError

D. ReferenceError

Answer: B

94. Which statement creates a new promise in JavaScript?

A. var promise = Promise()

B. var promise = new Promise(function(resolve, reject) {});

C. var promise = Promise(resolve, reject);

D. var promise = new Promise();

Answer: B

95. What does the reduce() method do for an array?

A. It reduces the size of an array.

B. It applies a function against an accumulator and each element in the array to reduce it to a single value.

C. It removes the first element from an array.

D. It reduces the number of elements in an array based on a condition.

Answer: B

96. How do you make a deep copy of an object in JavaScript?

A. Object.assign({}, obj)

B. JSON.parse(JSON.stringify(obj))

C. obj.clone()

D. obj.copy()

Answer: B

97. What is the output of console.log(typeof undefined)?

A. “undefined”

B. “object”

C. “null”

D. “NaN”

Answer: A

98. Which operator can be used to conditionally execute expressions?

A. &&

B. ||

C. !

D. ? : (Ternary operator)

Answer: D

99. How can you check if a variable x is a number in JavaScript?

A. typeof x === ‘number’

B. x instanceof Number

C. isNaN(x)

D. Number.isNumber(x)

Answer: A

100. What does the finally block do in a try…catch statement?

A. Executes code after the try block only if an exception occurs.

B. Executes code after the try and catch blocks, regardless of whether an exception was thrown.

C. Prevents further execution in case of an error.

D. Finalizes object cleanup if an exception is thrown.

Answer: B

JavaScript Explained Quick Tips

1. Correct syntax for referring to an external script called “script.js”:

  • Use <script src=”script.js”></script> to link an external JavaScript file. This element is typically placed in the HTML document’s head or body.

2. Correct way to write an array in JavaScript:

  • Arrays are written with square brackets. For example, var colors = [“red”, “green”, “blue”];.

3. Role of the finally block in a try…catch statement:

  • The finally block executes after the try and catch blocks, regardless of whether an exception was thrown or caught. It’s often used for cleanup code.

4. Operator to check both value and type:

  • The === operator checks for equality in both value and type, unlike ==, which only checks for value.

5. Output of console.log(0.1 + 0.2 == 0.3):

  • This will output false due to floating-point precision issues in JavaScript.

6. Writing an if statement in JavaScript:

  • The syntax is if (condition) { /* code to execute if condition is true */ }.

7. Method to convert JSON data to a JavaScript object:

  • JSON.parse() method is used to parse a JSON string, constructing the JavaScript value or object described by the string.

8. Starting a for loop:

  • A typical for loop starts with for (initialization; condition; increment) { /* code to execute on each iteration */ }.

9. Method to add new items to the end of an array:

  • The push() method adds one or more elements to the end of an array and returns the new length of the array.

10. Declaring a JavaScript variable that cannot be re-assigned:

  • The const keyword is used for variables whose values are not intended to be re-assigned.

11. Adding a comment in JavaScript:

  • Single-line comments are added with //, and multi-line comments use /* */.

12. Output of console.log(typeof “Hello”):

  • This statement returns “string” as typeof operator returns the type of the operand.

13. Writing a comment in JavaScript:

  • Comments can be single-line (// comment here) or multi-line (/* comment here */).

14. Handling asynchronous operations in JavaScript:

  • Asynchronous operations can be handled using callbacks, Promises, and async/await.

15. JavaScript tool for conditional execution:

  • Conditional execution can be achieved using if…else statements, switch, and ternary (condition ? exprIfTrue : exprIfFalse) operators.

16. Stopping the execution of a loop:

  • The break statement is used within loop statements (for, while, do…while, switch) to terminate the loop.

17. Method to combine two arrays:

  • The concat() method is used to merge two or more arrays by returning a new array.

18. Selecting elements with class name “example”:

  • Use document.getElementsByClassName(“example”) or document.querySelectorAll(“.example”).

19. What this keyword refers to in a function:

  • In JavaScript, this refers to the object that is executing the current function, which varies depending on the function’s calling context.

20. JavaScript data types:

  • JavaScript has several data types, including Number, String, Boolean, Object, Function, and Symbol. ‘Float’ is not a separate data type in JavaScript.

21. Creating a new Date object in JavaScript:

  • A new Date object is created using new Date(). This can represent the current date and time or a specific date/time.

22. Method for sending requests to a web server without reloading the page:

  • The fetch() API or XMLHttpRequest() can be used for making asynchronous HTTP requests.

23. Checking if a variable is an array:

  • Use Array.isArray(variable) to determine if a variable is an array.

24. Declaring a JavaScript variable:

  • Variables can be declared using var, let, or const.

25. Purpose of addEventListener method:

  • It’s used to attach an event handler to a specific element without overwriting existing event handlers.

26. Defining an anonymous function:

  • An anonymous function can be defined using function expressions like var myFunc = function() { /* code */ } or arrow functions var myFunc = () => { /* code */ }.

27. Accessing an HTML element by its ID using JavaScript:

  • Use document.getElementById(“id”) to access an element by its ID.

28. Writing a loop that repeats 5 times:

  • A for loop like for (var i = 0; i < 5; i++) { /* code */ } will repeat 5 times.

29. Output of console.log(1 + “2” + “2”):

  • This will output “122”. The numbers are treated as strings and concatenated.

30. Creating an object in JavaScript:

  • An object can be created using object literals like var obj = { property1: value1, property2: value2 };.

31. Removing the last element from an array:

  • The pop() method removes the last element from an array and returns that element.

32. What is a closure in JavaScript?

  • A closure is a function that has access to its own scope, the scope of the outer function, and the global scope.

33. Meaning of NaN in JavaScript:

  • NaN stands for ‘Not a Number’. It is a value representing a quantitative result that can’t be represented as a number.

34. Result of “10” == 10 in JavaScript:

  • It returns true because == compares values after type coercion.

35. Method to round a number to the nearest integer:

  • The Math.round() function is used to round a number to the nearest integer.

36. Serializing an object into a JSON string:

  • The JSON.stringify() method is used for this purpose.

37. Adding elements to the beginning of an array:

  • The unshift() method adds one or more elements to the beginning of an array.

38. Storing data in the browser’s local storage:

  • Use localStorage.setItem(‘key’, ‘value’); to store data.

39. Declaring a constant in JavaScript:

  • Constants are declared using the const keyword, e.g., const MY_CONSTANT = value;.

40. Delaying the execution of a function:

  • setTimeout() is used to delay the execution of a function by a specified number of milliseconds.

41. Finding the length of a string:

  • The .length property is used, e.g., “Hello”.length.

42. The this keyword in JavaScript:

  • this refers to the object that is executing the current function. Its value depends on the function’s execution context.

43. Output of console.log(typeof [1,2,3]):

  • The output will be “object” as arrays in JavaScript are objects.

44. Sorting the elements of an array:

  • The sort() method sorts the elements of an array in place and returns the sorted array.

45. Correct syntax for creating a promise:

  • A promise is created using new Promise(function(resolve, reject) { /* code */ });.

46. Creating a function in JavaScript:

  • A function can be created using a function declaration (e.g., function myFunc() { /* code */ }) or a function expression.

47. Result of Boolean(null):

  • It returns false as null is a falsy value in JavaScript.

48. Checking if a variable is an instance of a class:

  • Use the instanceof operator, e.g., x instanceof Y.

49. JavaScript operator for strict inequality:

  • The !== operator checks for strict inequality (not equal value or not equal type).

50. Getting the total number of arguments passed to a function:

  • Use the arguments.length property inside the function.

51. Converting the string “123” into a number:

  • Use Number(“123”) or parseInt(“123”).

52. Purpose of the Array.map() method:

  • It creates a new array populated with the results of calling a provided function on every element in the calling array.

53. What document.querySelector() method returns:

  • It returns the first Element within the document that matches the specified selector.

54. Deep copying an object in JavaScript:

  • Use JSON.parse(JSON.stringify(object)) for a deep copy of an object.

55. Output of console.log(“Hello” || “World”):

  • It outputs “Hello”. The logical OR (||) operator returns the first truthy operand.

56. Removing the first element from an array:

  • The shift() method removes the first element from an array and returns that element.

57. Event triggered when a user clicks on an HTML element:

  • The click event is triggered.

58. What is the output of console.log(1 + “2” + “2”)?

  • Output: “122”. This is due to string concatenation. JavaScript converts the number 1 to a string and concatenates the other strings, resulting in “122”.

59. How do you create an object in JavaScript?

  • An object in JavaScript can be created using object literals, e.g., var obj = { property1: value1, property2: value2 };.

60. Which method can be used to remove the last element from an array and return that element?

  • The pop() method is used to remove the last element from an array and return that element.

61. What is a closure in JavaScript?

  • A closure is a function that has access to the parent scope, even after the parent function has closed.

62. What does NaN stand for in JavaScript?

  • NaN stands for ‘Not a Number’. It is a value representing something that is not a number, though it is of type number.

63. What is the result of “10” == 10 in JavaScript?

  • The result is true. The == operator performs type coercion and only checks for value equality, not type.

64. Which method is used to round a number to the nearest integer?

  • Math.round() is used for rounding a number to the nearest integer.

65. Which method is used to serialize an object into a JSON string in JavaScript?

  • JSON.stringify() is used to convert an object into a JSON string.

66. What method is used to add one or more elements to the beginning of an array?

  • The unshift() method adds one or more elements to the beginning of an array.

67. Which statement correctly stores data in the browser’s local storage?

  • localStorage.setItem(‘key’, ‘value’) is used to store data in the browser’s local storage.

68. How do you declare a constant in JavaScript?

  • Constants are declared using the const keyword, e.g., const CONSTANT_NAME = value;.

69. Which of these methods can be used to delay the execution of a function in JavaScript?

  • setTimeout() is used to delay the execution of a function for a specified number of milliseconds.

70. How do you find the length of a string in JavaScript?

  • The length of a string can be found using the .length property, e.g., “Hello”.length.

71. Which of the following is true about the this keyword in JavaScript?

  • this refers to the object that is executing the current function. It varies depending on how a function is called.

72. What will the following code return: console.log(typeof [1,2,3])?

  • The output will be “object”. In JavaScript, arrays are technically objects.

73. Which method is used to sort the elements of an array?

  • The sort() method is used to sort the elements of an array.

74. What is the correct syntax for creating a promise in JavaScript?

  • A promise is created using the syntax new Promise(function(resolve, reject) { /* executor */ });.

75. How do you create a function in JavaScript?

  • A function can be created using a function declaration, e.g., function myFunction() { /* code */ }, or a function expression.

76. What will the following statement return? Boolean(null)

  • This will return false, as null is a falsy value in JavaScript.

77. How can you check if a variable x is an instance of a class Y?

  • You can use the instanceof operator, e.g., x instanceof Y.

78. Which is the correct JavaScript operator for strict inequality?

  • The !== operator is used for strict inequality, checking both value and type.

79. How can you get the total number of arguments passed to a function?

  • Within a function, you can use arguments.length to get the total number of arguments passed to it.

80. How can you convert the string “123” into a number?

  • You can use Number(“123”) or parseInt(“123”) to convert the string “123” into a number.

81. What is the purpose of the Array.map() method?

  • The map() method creates a new array with the results of calling a provided function on every element in the calling array.

82. What does the document.querySelector() method return?

  • It returns the first Element within the document that matches the specified selector or group of selectors.

83. In JavaScript, which of these is used for deep copying an object?

  • JSON.parse(JSON.stringify(object)) is used for deep copying an object.

84. What will be the output of console.log(“Hello” || “World”)?

  • The output will be “Hello”. In JavaScript, the logical OR (||) operator returns the value of the first truthy operand.

85. Which method is used to remove the first element from an array and return that element?

  • The shift() method is used for this purpose.

86. Which event is triggered when a user clicks on an HTML element?

  • The click event is triggered.

87. What is the output of console.log(1 + “2” + 3)?

  • The output will be “123”. The operation is processed from left to right, treating numbers as strings once a string is encountered.

88. What is the correct syntax for a JavaScript arrow function?

  • The syntax is (parameters) => { /* code */ }.

89. What does the Array.filter() method do?

  • It creates a new array with all elements that pass the test implemented by the provided function.

90. Which method is used to combine the strings of two or more strings in JavaScript?

  • The concat() method is used for this purpose.

91. What does the forEach() method do in JavaScript?

  • The forEach() method executes a provided function once for each array element.

92. What is Event Propagation in JavaScript?

  • Event propagation is the way some types of events will automatically call the same event on the parent elements.

93. How is a try…catch block used in JavaScript?

  • It’s used to mark a block of statements to try and to specify a response, should an exception be thrown.

94. Which JavaScript method is used for rounding a number down to its nearest integer?

  • The Math.floor() method is used for this purpose.

95. What does the map() method return in JavaScript?

  • It returns a new array with the results of calling a provided function on every element in the calling array.

96. What will the following code return? console.log(“10” === 10)

  • This will return false as the === operator checks for both value and type equality.

97. How can you convert a string to an integer in JavaScript?

  • You can use parseInt(string) or Number(string) to convert a string to an integer.

98. Which of these values is considered falsy in JavaScript?

  • Values like 0, “” (empty string), null, undefined, false, and NaN are considered falsy.

99. How do you declare a Read-Only property in a JavaScript object?

  • You can use Object.defineProperty() to declare a read-only property by setting its writable attribute to false.

100. What is the purpose of the bind() method in JavaScript?

  • The bind() method creates a new function that, when called, has its this keyword set to the provided value.

101. How do you find the type of a variable in JavaScript?

  • Use the typeof operator, e.g., typeof variable.

102. What is the output of console.log(“1” – – “1”)?

  • The output will be 2. The minus signs are treated as subtraction operators, converting the strings to numbers.

103. Which method is used to join two or more strings in JavaScript?

  • The concat() method is used to join two or more strings.

104. How do you select all paragraph elements in a document?

  • Use document.querySelectorAll(‘p’) to select all paragraph elements.

105. What is the default behavior of a <form> element’s submit action in HTML?

  • By default, submitting a form results in a page reload and data being sent to the server.

106. What is the method to parse a JSON string into a JavaScript object?

  • JSON.parse() is used to convert a JSON string into a JavaScript object.

107. How do you declare a JavaScript variable that can change in value?

  • Use let or var to declare a variable that can change in value.

108. How do you find the element with an ID of “demo”?

  • Use document.getElementById(‘demo’) to select the element with the ID of “demo”.