Which of the following is not a
primitive data type in JavaScript?
a) Number
b) String
c) Boolean
d) Object
What does the “typeof” operator do
in JavaScript?
a) Returns the data type of a variable
b) Checks if a variable is defined
c) Assigns a value to a variable
d) Concatenates two strings
What is the output of the following
code:
console.log(2 + “2”);
a) “4”
b) “22”
c) 4
d) 22
Which of the following is not a
comparison operator in JavaScript?
a) ==
b) ===
c) !=
d) =<
What is the output of the following
code:
var x = 5;
console.log(x++);
a) 4
b) 5
c) 6
d) Error
What is the output of the following
code:
var x = true;
console.log(!x);
a) true
b) false
c) undefined
d) Error
What does the “NaN” value
represent in JavaScript?
a) Not a number
b) Null value
c) Undefined value
d) Boolean value
What is the output of the following
code:
var x = 5;
var y = “5”;
console.log(x == y);
a) true
b) false
c) undefined
d) Error
What is the correct way to declare a
variable in JavaScript?
a) var x = 5;
b) variable x = 5;
c) x = 5;
d) let x = 5;
What does the “this” keyword refer
to in JavaScript?
a) The current function
b) The global object
c) The object that the function belongs to
d) The parent object of the current object
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x.length);
a) 1
b) 2
c) 3
d) 4
What is the output of the following
code:
console.log(typeof NaN);
a) “number”
b) “string”
c) “undefined”
d) “NaN”
Explanation: Although NaN stands for “Not a Number”, its type in JavaScript is
actually “number”.
What does the “forEach” method do
in JavaScript?
a) Adds a new element to the end of an array
b) Removes an element from the beginning of an array
c) Executes a function once for each element in an array
d) Reverses the order of the elements in an array
What is the output of the following
code:
console.log(2 ** 3);
a) 5
b) 6
c) 8
d) 9
What is the correct syntax for a “for”
loop in JavaScript?
a) for (var i = 0; i < 5; i++)
b) for (i = 0; i < 5; i++)
c) for (var i = 5; i > 0; i–)
d) for (i = 5; i > 0; i–)
What is the output of the following
code:
var x = 5;
var y = “5”;
console.log(x === y);
a) true
b) false
c) undefined
d) Error
What is the difference between
“==” and “===” operators in
JavaScript?
a) They are interchangeable
b) “==” performs a strict comparison, while “===” performs a loose comparison
c) “===” performs a strict comparison, while “==” performs a loose comparison
d) They both perform the same type of comparison
What is the output of the following
code:
var x = 10;
var y = “5”;
console.log(x – y);
a) 5
b) 10
c) 15
d) “105”
What is the output of the following
code:
var x = [1, 2, 3];
var y = […x];
console.log(y);
a) [1, 2, 3]
b) [3, 2, 1]
c) [1, 2]
d) Error
What is the output of the following
code:
console.log(Math.random());
a) 0
b) 0.5
c) 1
d) A random number between 0 and 1
What is the difference between “let”
and “const” keywords in JavaScript?
a) They are interchangeable
b) “let” variables cannot be reassigned, while “const” variables can
c) “const” variables cannot be reassigned, while “let” variables can
d) “let” and “const” both refer to constant variables
Which of the following is not a data
type in JavaScript?
a) Boolean
b) String
c) Number
d) Character
What is the output of the following
code:
console.log(“5” + 5);
a) “10”
b) 10
c) “55”
d) Error
Answer: c) “55”
Explanation: When you use the “+” operator with a string and a number, JavaScript
converts the number to a string and concatenates it to the string.
What is the difference between
“var” and “let” keywords in
JavaScript?
a) They are interchangeable
b) “var” variables cannot be reassigned, while “let” variables can
c) “let” variables have block scope, while “var” variables have function scope
d) “var” and “let” both refer to constant variables
What is the output of the following
code:
var x = 10;
if (true) {
var x = 5;
console.log(x);
a) 10
b) 5
c) undefined
d) Error
Answer: b) 5
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x[3]);
a) 3
b) undefined
c) Error
d) NaN
Which of the following is not a valid
way to declare a function in
JavaScript?
a) function myFunction() {}
b) var myFunction = function() {}
c) () => {}
d) function = {}
What is the difference between
“==” and “===” operators in
JavaScript?
a) They are interchangeable
b) “==” checks for value equality, while “===” checks for value and type equality
c) “===” checks for value equality, while “==” checks for value and type equality
d) They both perform the same operation
What is the output of the following
code:
console.log(typeof undefined);
a) “undefined”
b) “null”
c) “object”
d) “string”
What is the output of the following
code:
console.log(1 + “2” + 3);
a) “123”
b) 6
c) “15”
d) Error
Which of the following is not a loop
in JavaScript?
a) for
b) while
c) do…while
d) next
Answer: d) next
Explanation: “next” is not a loop in JavaScript. The correct loop keywords are “for”,
“while”, and “do…while”.
Which of the following is not a valid JavaScript array method?
a) push()
b) pop()
c) shift()
d) slice()
What is the output of the following
code:
console.log(typeof []);
a) “array”
b) “object”
c) “array[]”
d) “undefined”
What is the output of the following
code:
var x = 10;
function foo() {
console.log(x);
var x = 5;
foo();
a) 10
b) 5
c) undefined
d) Error
What is the output of the following
code:
var x = 1;
function foo() {
var x = 2;
function bar() {
console.log(x);
return bar;
var baz = foo();
baz();
a) 1
b) 2
c) undefined
d) Error
What is the output of the following
code:
console.log(“5” == 5);
a) true
b) false
c) Error
d) NaN
Which of the following is not a valid
way to declare a variable in
JavaScript?
a) var x;
b) let y;
c) const z;
d) variable w;
What is the output of the following
code:
console.log(typeof null);
a) “null”
b) “object”
c) “undefined”
d) Error
What is the output of the following
code:
console.log(“Hello”.charAt(1));
a) “H”
b) “e”
c) “l”
d) “o”
What is the output of the following
code:
var x = 5;
function foo() {
console.log(x);
function bar() {
var x = 10;
foo();
bar();
a) 5
b) 10
c) undefined
d) Error
What is the output of the following
code:
console.log(2 + 3 + “4”);
a) “54”
b) “9”
c) “234”
d) Error
Which of the following is not a valid
way to create a JavaScript array?
a) var arr = [];
b) var arr = new Array();
c) var arr = Array();
d) var arr = {1, 2, 3};
What is the output of the following
code:
console.log(NaN == NaN);
a) true
b) false
c) undefined
d) Error
What is the output of the following
code:
var x = 5;
var y = x++;
console.log(y);
a) 4
b) 5
c) 6
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
var y = x.slice(1);
console.log(y);
a) [1, 2]
b) [2, 3]
c) [1, 3]
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x.length);
a) 1
b) 2
c) 3
d) 4
What is the output of the following
code:
var x = “hello”;
console.log(x.charAt(0));
a) “h”
b) “e”
c) “l”
d) “o”
What is the output of the following
code:
var x = 5;
console.log(typeof x);
a) “number”
b) “string”
c) “boolean”
d) “undefined”
What is the output of the following
code:
var x = “5”;
var y = 2;
console.log(x + y);
a) “7”
b) “52”
c) 7
d) 52
What is the output of the following
code:
var x = [1, 2, 3];
x.push(4);
console.log(x);
a) [1, 2, 3]
b) [2, 3, 4]
c) [1, 2, 3, 4]
d) Error
What is the output of the following code:
var x = 10;
var y = “5”;
console.log(x – y);
a) 5
b) 10
c) 15
d) NaN
What is the output of the following code:
var x = “hello”;
console.log(x.toUpperCase());
a) “HELLO”
b) “Hello”
c) “hello”
d) Error
What is the output of the following code:
var x = true;
var y = false;
console.log(x || y);
a) true
b) false
c) Error
d) NaN
What is the output of the following code:
var x = [1, 2, 3];
console.log(x[0]);
a) 1
b) 2
c) 3
d) [1, 2, 3]
What is the output of the following
code:
var x = 5;
var y = “10”;
console.log(x + y);
a) 15
b) “15”
c) “510”
d) 510
What is the output of the following
code:
var x = [1, 2, 3];
x.push(4);
console.log(x);
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) Error
What is the output of the following
code:
var x = “10”;
var y = “5”;
console.log(x + y);
a) 15
b) “15”
c) “105”
d) 105
What is the output of the following
code:
var x = 10;
console.log(typeof x);
a) number
b) string
c) boolean
d) undefined
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x.length);
a) 0
b) 1
c) 2
d) 3
What is the output of the following
code:
var x = “10”;
var y = “5”;
console.log(x – y);
a) 5
b) “5”
c) “10”
d) NaN
What is the output of the following
code:
var x = 5;
console.log(++x);
a) 5
b) 6
c) NaN
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x[1]);
a) 1
b) 2
c) 3
d) Error
What is the output of the following
code:
var x = 10;
if (x == “10”) {
console.log(“Equal”);
} else {
console.log(“Not equal”);
a) Equal
b) Not equal
c) Undefined
d) Error
What is the output of the following
code:
var x = “hello”;
console.log(x.toUpperCase());
a) “hello”
b) “HELLO”
c) “Hello”
d) Error
What is the output of the following
code:
var x = true;
var y = false;
console.log(x || y);
a) true
b) false
c) null
d) Error
What is the output of the following
code:
var x = “5”;
console.log(typeof x);
a) “string”
b) “number”
c) “boolean”
d) “undefined”
What is the output of the following
code:
var x = 3;
var y = “4”;
console.log(x + y);
a) “34”
b) “7”
c) 7
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
x.push(4);
console.log(x);
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) Error
What is the output of the following
code:
var x = 5;
if (x === “5”) {
console.log(“Equal”);
} else {
console.log(“Not equal”);
a) Equal
b) Not equal
c) Undefined
d) Error
What is the output of the following
code:
var x = 10;
while (x > 0) {
console.log(x);
x–;
a) 1 2 3 4 5 6 7 8 9 10
b) 10 9 8 7 6 5 4 3 2 1
c) 0
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
var y = x;
y.push(4);
console.log(x);
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) Error
What is the output of the following
code:
var x = 10;
var y = x++;
console.log(y);
a) 9
b) 10
c) 11
d) Error
What is the output of the following
code:
var x = 5;
var y = 3;
console.log(x *= y);
a) 8
b) 15
c) 12
d) 25
What is the output of the following
code:
var x = “10”;
var y = +”3″;
console.log(x + y);
a) “103”
b) “13”
c) 13
d) Error
What is the output of the following
code:
var x = 0;
while (x < 5) {
console.log(x);
x += 2;
a) 0 2 4 6 8
b) 0 2 4
c) 2 4 6 8
d) Error
What is the output of the following
code:
console.log(“5” + 2);
a) “7”
b) 7
c) “52”
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x.slice(1));
a) [1, 2]
b) [2, 3]
c) [1, 2, 3]
d) Error
What is the output of the following
code:
var x = 5;
var y = 3;
if (x > y) {
console.log(“x is greater than y”);
} else {
console.log(“y is greater than x”);
}
a) “x is greater than y”
b) “y is greater than x”
c) 2
d) Error
What is the output of the following
code:
var x = 10;
function foo() {
console.log(x);
var x = 5;
console.log(x);
foo();
a) 10 5
b) 5 10
c) Error
d) undefined 5
What is the output of the following
code:
console.log(typeof null);
a) “null”
b) “object”
c) “undefined”
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
var y = x;
y.push(4);
console.log(x);
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) Error
What is the output of the following
code:
console.log(5 == “5”);
a) true
b) false
c) Error
d) undefined
What is the output of the following
code:
var x = 10;
function foo() {
console.log(x);
foo();
var x = 5;
a) 10
b) 5
c) undefined
d) Error
What is the output of the following
code:
var x = 5;
var y = 3;
var z = x++ – y–;
console.log(z);
a) 2
b) 3
c) 4
d) 5
What is the output of the following
code:
console.log(“hello” + 3);
a) “hello3”
b) 3
c) “hello”
d) Error
What is the output of the following
code:
console.log(true && “hello”);
a) true
b) “hello”
c) false
d) undefined
What is the output of the following
code:
var x = 5;
function foo() {
console.log(x);
var x = 10;
foo();
a) 5
b) 10
c) undefined
d) Error
What is the output of the following
code:
console.log(typeof NaN);
a) “number”
b) “string”
c) “undefined”
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
var y = x.slice(0, 2);
console.log(y);
a) [1, 2]
b) [2, 3]
c) [1, 2, 3]
d) Error
What is the output of the following
code:
console.log(“3” + 2);
a) “32”
b) “5”
c) 5
d) Error
What is the output of the following
code:
console.log(null == undefined);
a) true
b) false
c) NaN
d) Error
What is the output of the following
code:
var x = 5;
function foo() {
console.log(x);
foo();
a) 5
b) undefined
c) null
d) Error
What is the output of the following
code:
console.log(0.1 + 0.2 == 0.3);
a) true
b) false
c) NaN
d) Error
What is the output of the following
code:
var x = {name: “John”, age: 30};
console.log(Object.keys(x));
a) {name: “John”, age: 30}
b) [“name”, “age”]
c) “John,30”
d) Error
What is the output of the following
code:
console.log(typeof NaN);
a) “number”
b) “string”
c) “NaN”
d) “undefined”
What is the output of the following
code:
console.log(“foo”.indexOf(“o”));
a) 0
b) 1
c) 2
d) -1
What is the output of the following
code:
var x = 5;
var y = x++;
console.log(x, y);
a) 5, 5
b) 6, 5
c) 6, 6
d) Error
What is the output of the following
code:
var x = [“a”, “b”, “c”];
x.splice(1, 1);
console.log(x);
a) [“a”, “b”, “c”]
b) [“a”, “c”]
c) [“b”, “c”]
d) Error
What is the output of the following
code:
console.log(10 < 9 < 8);
a) true
b) false
c) NaN
d) Error
Answer: a) true
What is the output of the following
code:
var x = [1, 2, 3];
var y = x.map(function(n) { return n * 2; });
console.log(y);
a) [1, 2, 3]
b) [2, 4, 6]
c) [1, 4, 9]
d) Error
What is the output of the following
code:
console.log(typeof null);
a) “object”
b) “null”
c) “undefined”
d) “string”
What is the output of the following
code:
var x = 5;
var y = “5”;
console.log(x == y);
a) true
b) false
c) NaN
d) Error
What is the output of the following
code:
var x = 5;
var y = “5”;
console.log(x === y);
a) true
b) false
c) NaN
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
console.log(x.toString());
a) “1,2,3”
b) [1, 2, 3]
c) [“1”, “2”, “3”]
d) Error
What is the output of the following
code:
var x = 5;
var y = 3;
console.log(x %= y);
a) 1
b) 2
c) 3
d) 4
What is the output of the following
code:
console.log(typeof []);
a) “array”
b) “object”
c) “null”
d) “undefined”
What is the output of the following
code:
var x = [1, 2, 3];
x.push(4);
console.log(x);
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 3, 2, 1]
d) Error
What is the output of the following
code:
var x = “hello”;
var y = x.toUpperCase();
console.log(y);
a) “hello”
b) “HELLO”
c) “Hello”
d) Error
What is the output of the following
code:
var x = 5;
var y = “3”;
console.log(x + y);
a) 8
b) “53”
c) 53
d) Error
What is the output of the following
code:
var x = 10;
var y = 5;
console.log((x > y) && (y < 6));
a) true
b) false
c) TypeError
d) ReferenceError
What is the output of the following
code:
var x = “5”;
var y = “3”;
console.log(x + y);
a) 8
b) “53”
c) 53
d) Error
What is the output of the following
code:
var x = 10;
var y = “5”;
console.log(x + y);
a) 15
b) “105”
c) 105
d) Error
What is the output of the following
code:
var x = [1, 2, 3];
var y = [1, 2, 3];
console.log(x == y);
a) true
b) false
c) TypeError
d) ReferenceError
What is the output of the following
code:
var x = 10;
var y = 3;
console.log(x / y);
a) 3.33
b) 3.3333
c) 3.333333
d) 3
Which of the following is not a
primitive data type in JavaScript?
A) String
B) Number
C) Boolean
D) Array
Which of the following methods
removes the last element from an
array and returns that element?
A) push()
B) pop()
C) shift()
D) unshift()
What is the output of the following
code?
function foo() {
var a = b = 3;
foo();
console.log(“a defined? ” + (typeof a !== ‘undefined’));
console.log(“b defined? ” + (typeof b !== ‘undefined’));
A) a defined? true, b defined? true
B) a defined? false, b defined? true
C) a defined? true, b defined? false
D) a defined? false, b defined? false