JavaScript MCQ: JavaScript Multiple Choice Questions and Answers

JavaScript MCQ with answers and explanations for placement tests and job interviews. These solved JavaScript MCQ are useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our JavaScript MCQ ( JavaScript multiple Choice Questions ) focuses on all areas of JavaScript and its concept. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

If you want to learn JavaScript in detail you can follow these courses created by industry experts, Trial of some courses is free.

Guideline of JavaScript MCQ:

This JavaScript MCQ is intended for checking your JavaScript knowledge. It takes 1 hour to pass the JavaScript MCQ. If you don’t finish the JavaScript MCQ within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on JavaScript has features of randomization which feel you a new question set at every attempt.

In this JavaScript MCQ, we have also implemented a feature that not allowed the user to see the next question or finish the quiz without attempting the current JavaScript MCQ.

1 votes, 4 avg

You have 1 hours to take the JavaScript MCQs

Your time has been Over.


Javascript MCQ

Java Script

Javascript MCQ: Javascript Multiple Choice Questions and Answers

1 / 82

What type of scope does the end variable have in the code shown?
var start = 1;
if (start === 1) {
let end = 2;
}

2 / 82

You've written the code shown to log a set of consecutive values, but it instead results in the value 5, 5, 5, and 5 being logged to the console. Which revised version of the code would result in the value 1, 2, 3 and 4 being logged?
for (var i = 1; i <= 4; i++) {
setTimeout(function () {
console.log(i);
}, i * 10000);
}

3 / 82

You're adding error handling to the code shown. Which code would you include within the if statement to specify an error message?
function addNumbers(x, y) {
if (isNaN(x) || isNaN(y)) {
}
}

4 / 82

Which method cancels event default behavior?

5 / 82

Which of these is a valid variable name?

6 / 82

If you attempt to call a value as a function but the value is not a function, what kind of error would you get?

7 / 82

What is the result of running this statement?
console.log(typeof(42));

8 / 82

Which statement references the DOM node created by the code shown?
<p class="pull">lorem ipsum</p>

9 / 82

How do you add a comment to JavaScript code?

10 / 82

Why might you choose to make your code asynchronous?

11 / 82

Which method is called automatically when an object is initialized?

12 / 82

What does the following expression evaluate to?

[] == [];

13 / 82

What is the result in the console of running this code?
'use strict';
function logThis() {
this.desc = 'logger';
console.log(this);
}
new logThis();

14 / 82

What's one difference between the async and defer attributes of the HTML script tag?

15 / 82

What will the value of y be in this code:
const x = 6 % 2;
const y = x ? 'One' : 'Two';

16 / 82

Which statement creates a new object using the Person constructor?

17 / 82

Which expression evaluates to true?

18 / 82

What will this code log in the console?
function sayHello() {
console.log('hello');
}

console.log(sayHello.prototype);

19 / 82

For the following class, how do you get the value of 42 from an instance of X?
class X {
get Y() {
return 42;
}
}

20 / 82

When would you use a conditional statement?

21 / 82

. How would you use the TaxCalculator to determine the amount of tax on $50?
class TaxCalculator {
static calculate(total) {
return total * 0.05;
}
}

22 / 82

Which operator returns true if the two compared values are not equal?

23 / 82

What is the HTTP verb to request the contents of an existing resource?

24 / 82

Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?

25 / 82

Which keyword is used to create an error?

26 / 82

What is the result in the console of running the code shown?
var start = 1;
function setEnd() {
var end = 10;
}
setEnd();
console.log(end);

27 / 82

Which choice is an incorrect way to define an arrow function that returns an empty object?

28 / 82

What value does this code return?
let answer = true;
if (answer === false) {
return 0;
} else {
return 10;
}

29 / 82

What will be logged to the console?
'use strict';
function logThis() {
this.desc = 'logger';
console.log(this);
}
new logThis();

30 / 82

This program has a problem. What is it?

var a;
var b = (a = 3) ? true : false;

31 / 82

What is the result of running the statement shown?
let a = 5;
console.log(++a);

32 / 82

What would be the result in the console of running this code?
for (var i = 0; i < 5; i++) {
console.log(i);
}

33 / 82

Which concept is defined as a template that can be used to generate different objects that share some shape and/or behavior?

34 / 82

Which statement selects all img elements in the DOM tree?

35 / 82

Which class-based lifecycle method would be called at the same time as this effect Hook?

useEffect(() => {
// do things
}, []);

36 / 82

How is a forEach statement different from a for statement?

37 / 82

Which statement represents the starting code converted to an IIFE?

38 / 82

Which collection object allows unique value to be inserted only once?

39 / 82

Which method do you use to attach one DOM node to another?

40 / 82

What will this code print?
var v = 1;
var f1 = function () {
console.log(v);
};

var f2 = function () {
var v = 2;
f1();
};

f2();

41 / 82

0 && hi

42 / 82

Which choice is not a unary operator?

43 / 82

You need to match a time value such as 12:00:32. Which of the following regular expressions would work for your code?

44 / 82

Which property references the DOM object that dispatched an event?

45 / 82

Which statement is true about Functional Programming?

46 / 82

Why would you choose an asynchronous structure for your code?

47 / 82

What will be logged to the console?
var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
console.log(a.length);

48 / 82

What is one difference between collections created with Map and collections created with Object?

49 / 82

Which method converts JSON data to a JavaScript object?

50 / 82

Which variable is an implicit parameter for every function in JavaScript?

51 / 82

Which statement is true about the "async" attribute for the HTML script tag?

52 / 82

When would 'results shown' be logged to the console?

let modal = document.querySelector('#results');
setTimeout(function () {
modal.classList.remove('hidden');
}, 10000);

53 / 82

Review the code below. Which statement calls the addTax function and passes 50 as an argument?
function addTax(total) {
return total * 1.05;
}

54 / 82

. What is the value of dessert.type after executing this code?
const dessert = { type: 'pie' };
dessert.type = 'pudding';

55 / 82

How would you reference the text 'avenue' in the code shown?
let roadTypes = ['street', 'road', 'avenue', 'circle'];

56 / 82

Which of the following values is not a Boolean false?

57 / 82

Which statement is used to skip iteration of the loop?

58 / 82

What is the result in the console of running the code shown?
var Storm = function () {};
Storm.prototype.precip = 'rain';
var WinterStorm = function () {};
WinterStorm.prototype = new Storm();
WinterStorm.prototype.precip = 'snow';
var bob = new WinterStorm();
console.log(bob.precip);

59 / 82

Why is it usually better to work with Objects instead of Arrays to store a collection of records?

60 / 82

What is the result of running this code?
sum(10, 20);
diff(10, 20);
function sum(x, y) {
return x + y;
}

let diff = function (x, y) {
return x - y;
};

61 / 82

For the following class, how do you get the value of 42 from "X" ?
class X {
get Y() {
return 42;
}
}
var x = new X();

62 / 82

How do you import the lodash library making it top-level Api available as the "_" variable?

63 / 82

How does a function create a closure?

64 / 82

Which of the following is not a keyword in JavaScript?

65 / 82

Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?

66 / 82

Why would you include a "use strict" statement in a JavaScript file?

67 / 82

When would the final statement in the code shown be logged to the console?
let modal = document.querySelector('#result');
setTimeout(function(){
modal.classList.remove('hidden);
}, 10000);
console.log('Results shown');

68 / 82

Which choice is valid example for an arrow function?

69 / 82

. You've written the event listener shown below for a form button, but each time you click the button, the page reloads. Which statement would stop this from happening?
button.addEventListener(
'click',
function (e) {
button.className = 'clicked';
},
false,
);

70 / 82

Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined. What does that mean?

71 / 82

. How many prototype objects are in the chain for the following array?
let arr = [];

72 / 82

What is the name of a function whose execution can be suspended and resumed at a later point?

73 / 82

What is the output of this code?
var obj;
console.log(obj);

74 / 82

Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?

75 / 82

Which of the following operators can be used to do a short-circuit evaluation?

76 / 82

After the following code, what is the value of a.length?
var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
console.log(a.length);

77 / 82

Which statement is the correct way to create a variable called rate and assign it the value 100?

78 / 82

What two values will this code print?
function printA() {
console.log(answer);
var answer = 1;
}
printA();
printA();

79 / 82

. Which Object method returns an iterable that can be used to iterate over the properties of an object?

80 / 82

Which statement creates a new function called discountPrice?

81 / 82

What is the result in the console of running this code?
function logThis() {
console.log(this);
}
logThis();

82 / 82

How does the forEach() method differ from a for statement?

Your score is

The average score is 0%

0%

Recommended Articles for you: