JavaScript Quiz

JavaScript Quiz

What is the result of the following code?

console.log(1 + “2” + 3 + 4);

a) “1234”

b) “10”

c) “6”

d) “124”

What is the result of the following code?

console.log(typeof null);

a) “object”

b) “null”

c) “undefined”

d) “boolean”

Which of the following is NOT a valid way to declare a variable in JavaScript?

a) let myVar = “hello”;

b) var myVar = “hello”;

c) const myVar = “hello”;

d) myVar = “hello”;

What is the output of the following code?

let arr = [1, 2, 3, 4];

console.log(arr.slice(1, 3));

a) [2, 3]

b) [1, 2]

c) [3, 4]

d) [2, 4]

What is the result of the following code?

const a = 10;

a = 20;

console.log(a);

a) 10

b) 20

c) “const” keyword error

d) “let” keyword error

What is the result of the following code?

let num = 5;

num *= 10;

console.log(num);

a) 5

b) 10

c) 50

d) “num” keyword error

What is the result of the following code?

const obj = { name: “John”, age: 30 };

console.log(obj.name);

a) “John”

b) “age”

c) { name: “John”, age: 30 }

d) “undefined”

What is the output of the following code?

let arr = [1, 2, 3];

arr.push(4);

console.log(arr);

a) [1, 2, 3, 4]

b) [4, 3, 2, 1]

c) [1, 2, 3]

d) [1, 2, 4, 3]

Which of the following is NOT a valid data type in JavaScript?

a) string

b) boolean

c) number

d) float

What is the result of the following code?

console.log(5 == “5”);

a) true

b) false

c) “5” keyword error

d) “==” keyword error

JavaScript ANSWERS

What is the result of the following code?

console.log(1 + “2” + 3 + 4);

Answer: a) “1234”

What is the result of the following code?

console.log(typeof null);

Answer: a) “object”

Which of the following is NOT a valid way to declare a variable in JavaScript?

Answer: d) myVar = “hello”; (this is an assignment statement, not a declaration)

What is the output of the following code?

let arr = [1, 2, 3, 4];

console.log(arr.slice(1, 3));

Answer: a) [2, 3]

What is the result of the following code?

const a = 10;

a = 20;

console.log(a);

Answer: c) “const” keyword error

What is the result of the following code?

let num = 5;

num *= 10;

console.log(num);

Answer: c) 50

What is the result of the following code?

const obj = { name: “John”, age: 30 };

console.log(obj.name);

Answer: a) “John”

What is the output of the following code?

let arr = [1, 2, 3];

arr.push(4);

console.log(arr);

Answer: a) [1, 2, 3, 4]

Which of the following is NOT a valid data type in JavaScript?

Answer: d) float (JavaScript only has one numeric data type, which is “number”)

What is the result of the following code?

console.log(5 == “5”);

Answer: a) true (loose comparison between a number and a string will result in true if their values are equal, regardless of their data type)