1. How do you create an object in JavaScript?
2. What is the value of x? var a = false; var x = a ? “A” : “B”;
3. How to return the first value of this array? var myArr = [1, 2, 3, 4, 5]; var myVal = ...
4. Which is NOT a way to create a loop in javascript?
5. Where do you use the 'break' statement?
6. In an array object, what is the key of the first value?
7. Which statement loops through an array?
8. You use the Math.pow() method to:
9. Value of ('dog'.length)?
10. How do you round the number 7.25, to the nearest whole number?
11. What does the 'break' statement do?
12. How do you define a function called 'fName'?
13. Which is not a reserved word?
14. Correct way to create an instance of Person?
15. What is the value of a : var a = 3; var b = 2; var c = a; var a=b=c=1;
16. What is the value of the array myArr after execution of the following code: var myArr = [1,2,3,4,5]; myArr.shift();
17. Which event fires whenever a control loses focus?
18. var a = {1: 'one',2:'two',3:'three'}; var b = Object.keys(a); What's the value of b?
19. Which is the equivalent of the following. if (a) { x = b; } else { x = c; }
20. The function call Math.ceil(3.5) returns:
21. Which variable type does not exist in JavaScript?
22. Which is a correct method to create a new array?
23. To what type are values converted internally when evaluating a conditional statement?
24. What does ''2'' + 3 + 4 evaluate to?
25. Consider this code: var x = ['Hello']; What value will 'x[1]' return?
26. Result of the following expression: var a = 'test'; console.log(!!a);
27. The loop isn't working. What's the problem? var foos = ['a', 'b', 'c' , 'd', 'e']; var bars = ['x', 'y', 'z']; for (var i = 0; i < foos.length; i++) { var foo = foos[i]; for (var i = 0; i < bars.length; i++) { var bar = bars[i]; /* some code using `bar` */ } }
var foos = ['a', 'b', 'c' , 'd', 'e']; var bars = ['x', 'y', 'z']; for (var i = 0; i < foos.length; i++) { var foo = foos[i]; for (var i = 0; i < bars.length; i++) { var bar = bars[i]; /* some code using `bar` */ } }
28. How do you write a conditional statement that will only execute the contained code if variable x has a value 5 of type number?
29. In the loop, 'for (first clause; second clause; third clause) { statements; }' What does the second clause represent?
30. Syntax for an object literal (with no properties)?
31. Functions in javascript are always ..
32. Which is not a method in the 'JSON' object according to the ECMAScript specification?
33. What is the value of 'x' ? var a = true, b = false, x = !(a===b) ? !a : b;
34. Given a variable named stringVar with a string value, what does the following do? stringVar.toUpperCase();
35. Which is an example of (only) an object literal in Javascript?
36. Primitive types are passed by :
37. Which is not a primitive data type in JavaScript?
38. Result of the following statement: typeof 'x';
39. What is the value of x? var x = 10/0;
40. var y = 3, x = y++; What is the value of x?
41. What is the value of x? var x = typeof new String('abc');
42. Difference between the 'var' keyword and the new 'let' keyword which appears in ECMAScript 6 ?
43. Which String prototype method is capable of removing a character from a string?
44. Which type does NOT exist in javascript?
45. What's the output? 1 + 5 + ' bottles of milk';
46. Which fact is true about the keyword 'default'?
47. var x = Math.ceil(10.126); What is the value of x?
48. var obj1 = {}; var obj2 = {}; What is the value of (obj1 === obj2)
49. [] === [] evaluates to
50. What does the following return? Number(null);
51. Which is NOT a valid way to write a loop that will iterate over the values in the array in variable 'myArray'?
52. What is the value of x? var x = typeof NaN;
53. Which is not a reserved word in the language?
54. Which String prototype method takes a regular expression?
55. Evaluate: '10' - (17).toString()
56. Evaluate: undefined + 2
57. What does the >>> operator do?
58. Object.keys(x)
59. console.log( typeof [1,2] ) will print out:
60. After the following code: var a = function(){ this.b = 1; this.deleteMe = function(){ delete this; } }; var c = new a(); c.deleteMe(); What is the value of (String(c))?
61. var q = null; q++; What is q?
62. Value of x after the following code is run? var obj = { 0: 'who', 1: 'what', 2: 'idontknow'}; var x = 1 in obj;
63. function foo() { this = 'foo'; } var a = foo(); What will the preceding code produce?
64. Math.log(x) returns:
65. Correct syntax for creating a Date object for January 10, 1998?
66. What's the output? var test = function (firstName, surname) { this.Name.FirstName = firstName; this.Name.Surname = surname; } test.prototype = { Name: { FirstName: undefined, Surname: undefined } } var b = new test('john', 'doe'); var c = new test('bob', 'templeton'); console.log(b.Name.FirstName + ' ' + b.Name.Surname + ', ' + c.Name.FirstName + ' ' + c.Name.Surname);
67. What is the value of 'x' after the following code runs? var x; x++;
68. Evaluate: ![]+[]
69. Value of the variable `c` at the end of this script? var a = 1; var b = 2; var c = a || b;
70. What does this line display? alert(typeof(Array));
71. What does the following statement declares? var myArray = [[[]]];
72. var data = ['A', 'B', 'C', 'D']; data.unshift('X'); data.push('Y'); What does data look like?
73. How do you write 'Hello World' in an alert box?
74. What's the output? for (var i = 0; i < 5; i++) { (function(x) { setTimeout(function() { console.log(x); }, x * 1000 ); })(i); }
75. var x = 1.0; typeof x;
76. What's the output? (function(x) { return (function(y) { console.log(x); })(2) })(1);
77. The output for the code would be var a=5 , b=1 var obj = { a : 10 } with(obj) { alert(b) }
78. var colors=[{name:'red'}], car={name:'toyota'}; car.color=colors[0]; car.color.name='yellow'; Which is the value of colors[0].name?
79. What is logged? var x = (1 + '1') !== '11' || ('1' + 1) === 2; console.log(x);
80. Which is equivalent to: rowCount = rowCount + 1;
81. What the value will be returned as a result of this function call? function foo () { return true ? false : null; };
82. Javascript primitives are literal objects.
83. What's the output? (function(){ var a = b = 3; })(); console.log(' a defined? ' + (typeof a !== 'undefined'));)) console.log(' b defined? ' + (typeof b !== 'undefined'));))
84. function aaa() { return { test: 1 }; } alert(typeof aaa()); what does the above alert?
85. What is the value of x? var a = 'A'; var x = a.concat('B');
86. Which character ends a JavaScript statement?
87. What is the var statement used for?
88. Which of these is NOT a type of Error?
89. What defines a local scope?
90. How could you read the first character in a string?
91. Which statement lets you create custom exceptions?
92. Which is the correct output of the given code? var a = 20 + 'Example' + 10 + 'Test'; var b= 20 + 10 + 'Test' + 'Example' ; document.write(a, ''); document.write(b);
93. Which is the correct syntactical representation of a generator expression in JavaScript?
94. What's the output?
95. Analyze the code using the source property of Regular Expressions. What's the output? The regular expression is: enS
96. With regard to Math object in JavaScript 1.8, which are true?
97. What's the output? var vName='Kodak Camera' vName.indexOf('Camera')
98. Which is not a valid string method?
99. Consider the following image definition: Which will change the image to 'companylogo2.gif' when the page loads?
100. Performance-wise, which is the fastest way of repeating a string in JavaScript?
101. What's the output? rose found. index now at: 8
102. Which is not a valid method in generator-iterator objects in JavaScript?
103. What's the output? function testGenerator() { yield 'first'; document.write('step1'); yield 'second'; document.write('step2'); yield 'third'; document.write('step3'); } var g = testGenerator(); document.write(g.next()); document.write(g.next());
104. Which Array method in JavaScript runs a function on every item in the Array and collects the result from previous calls, but in reverse?
105. Which are not valid HTML events?
106. Final value of the variable bar in the following code? var foo = 9; bar = 5; (function() { var foo = 2; bar= 1; }()) bar = bar + foo;
107. Which methods can be used to make permalinks SEO friendly?
108. Which functions are used when adding CSS and jQuery codes on a WordPress plugin?
109. Which will echo the base URL of a WordPress site?
110. Consider the following JavaScript alert: Which will run the function when a user opens the page?
111. Final value of the variable apt? var apt=2; apt=apt<<2;
112. Analyze the following code snippet. What's the output? now
113. What does the following JavaScript code do?
114. Which statement is incorrect regarding HTML5 Web Worker?
115. What's the output? var foo = function foo() { console.log(foo === foo); }; foo();
116. Which is incorrect way of instantiating a date?
117. Which can be used to handle the user clicking on a node?
118. Correct way to read the 'age' property of a 'person' object?
119. What is the Promise?
120. What's the output? console.log(typeof a); console.log(typeof b); function a() { } var b = function () { };
121. How do you create a Date object in JavaScript?
122. Which Popup Boxes have support in JavaScript?
123. What is true about an Array?
124. How can you create a function with the JavaScript Function constructor ?
125. What method can't be used with a window object?
126. What command skips the rest of a case statement?
127. What's printed on the browser console by following code:- console.log(parseFloat('9. Hello World '));
128. Which of the following is true? var a = [var b = a var c = a.slice() a.push('date')
129. How do you locate the first X in a string variable named txt?
130. The second control statement in a for loop usually:
131. Which statement is the correct way to create a variable called rate and assign it the value 100?
132. What is the result of running this statement? Console.log(typeof 42);
133. How do you import the lodash library making it top-level Api available as the "_" variable?
134. Which choice is not a unary operator?
135. What is the output of this code? var obj; console.log(obj);
136. If your app receives data from a third-party API, which HTTP response header must the server specify to allow exceptions to the same-origin policy?
137. What is the output of this code? let x = 6 + 3 + '3'; console.log(x);
138. Which choice is a valid example of an arrow function, assuming c is defined in the outer scope?
139. Which choice is not an array method?
140. How can you attempt to access the property a.b on obj without throwing an error if a is undefined? let obj = {};
141. Given this code, which statement will evaluate to false? const a = { x: 1 }; const b = { x: 1 };
JavaScript MCQs | Topic-wise