0% found this document useful (0 votes)
2 views

JavaScript_MCQ_Coding_Snippets_2

Js coding snippets
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JavaScript_MCQ_Coding_Snippets_2

Js coding snippets
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

JavaScript MCQ

1. What will the following code print?

var a = 10;
var b = "5";
console.log(a + b);

Options:

a. 15
b. "105"
c. NaN
d. Error

2. What will be the output of the following code?


var x = 10;
var y = 20;
console.log(x == "10" && y == "20");

Options:

a. True
b. False
c. Undefined
d. SyntaxError

3. What is the result of the following code?


var a = [1, 2, 3];
var b = a;
b[0] = 100;
console.log(a[0]);

Options:

a. 1
b. 100
c. undefined
d. Error
4. What will be logged to the console?
var obj = { name: "John", age: 25 };
delete obj.name;
console.log(obj.name);

Options:

a. John
b. undefined
c. null
d. Error

5. Which of the following will throw an error?


var a = 10;
console.log(a++);

Options:

a. No error, it logs 10
b. SyntaxError
c. TypeError
d. ReferenceError

6. What will the following code output?


console.log(3 + 2 + "1");

Options:

a. "32"
b. "51"
c. "21"
d. 51

7. What is the output of the following code?


console.log(0 == false);

Options:

a. true
b. false
c. undefined
d. NaN
8. What will be the output of this code?
var a = 3;
function test() {
var a = 5;
console.log(a);
}
test();

Options:

a. 3
b. 5
c. undefined
d. ReferenceError

9. Which of the following will return true?


console.log([] == []);

Options:

a. true
b. false
c. undefined
d. Error

10. What will the output be for the following code?


var x = "Hello";
console.log(x.length);

Options:

a. 4
b. 5
c. "Hello"
d. Undefined
11. What does the following code print?
console.log(2 + "2" - 1);

Options:

a. "21"
b. 21
c. 3
d. NaN

12. What will this code print?


var a = [1, 2];
var b = a;
b.push(3);
console.log(a);

Options:

a. [1, 2]
b. [1, 2, 3]
c. undefined
d. Error

13. What is the output of the following?


console.log(null == undefined);

Options:

a. true
b. false
c. undefined
d. NaN

14. What will be the result of this code?


var a = 5;
var b = "5";
console.log(a === b);

Options:

a. true
b. false
c. undefined
d. NaN
15. What does the following code output?
console.log("5" - 3);

Options:

a. 53
b. 2
c. "2"
d. NaN

You might also like