Q
What will be the output of the following JavaScript code? Code: console.log('Hello' + 1 + 2);

Answer & Solution

Answer: Option A
Solution:
The output will be 'Hello12'. In JavaScript, the + operator is used for both addition and concatenation. Since the expression starts with a string, JavaScript treats the subsequent numbers as strings and concatenates them.
Related Questions on Average

What will be the output of the following JavaScript code? Code: let x = 45; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }

A). A) Even

B). B) Odd

C). C) 45

D). D) None of the above

What will be the output of the following JavaScript code? Code: let x = 35; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }

A). A) Even

B). B) Odd

C). C) 35

D). D) None of the above

What will be the output of the following JavaScript code? Code: let x = 40; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }

A). A) Even

B). B) Odd

C). C) 40

D). D) None of the above

What does the following JavaScript code snippet do? Code: let numbers = [1, 2, 3, 4, 5]; let sum = numbers.reduce((total, num) => total + num, 0); console.log(sum);

A). A) Finds the maximum number in numbers

B). B) Calculates the average of numbers in numbers

C). C) Sums all numbers in numbers

D). D) Checks if all numbers in numbers are even

What does the following JavaScript code snippet do? Code: let numbers = [1, 2, 3, 4, 5]; let min = Math.min(...numbers); console.log(min);

A). A) Calculates the sum of numbers in numbers

B). B) Finds the minimum number in numbers

C). C) Calculates the product of numbers in numbers

D). D) Checks if all numbers in numbers are even

What will be the output of the following JavaScript code? Code: let x = 25; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }

A). A) Even

B). B) Odd

C). C) 25

D). D) None of the above

What will be the output of the following JavaScript code? Code: console.log(typeof null);

A). A) Object

B). B) Null

C). C) Undefined

D). D) String

What will be the output of the following JavaScript code? Code: console.log(2 + 2 + '2');

A). A) 42

B). B) 22

C). C) 4'2'

D). D) '22'

What does the following JavaScript code snippet do? Code: let x = 'Hello'; console.log(x.toUpperCase());

A). A) Converts x to lowercase

B). B) Reverses the characters in x

C). C) Converts x to uppercase

D). D) Adds spaces to x

What will be the output of the following JavaScript code? Code: let x = 30; if (x % 2 === 0) { console.log('Even'); } else { console.log('Odd'); }

A). A) Even

B). B) Odd

C). C) 30

D). D) None of the above