Q
What will be the output of '5' + 2 - 1 in JavaScript?

Answer & Solution

Answer: Option A
Solution:
<div>When adding a string and a number in JavaScript, it concatenates the values as strings from left to right, resulting in '52'. Subtraction then occurs, converting '52' to a number, resulting in 52 - 1 = 51.</div>
Related Questions on Average

What is the value of x after executing the code: let x = 5; x *= 2 + 3;?

A). 10

B). 25

C). 13

D). 15

What will be the output of 10 + '2' - 1 in JavaScript?

A). '101'

B). '10'

C). NaN

D). Error

What is the result of '20' - 10 in JavaScript?

A). 10

B). '10'

C). NaN

D). 20

What will be the output of '2' + 2 + 2 in JavaScript?

A). '222'

B). 6

C). 4

D). Error

What will be the result of 10 + '5' in JavaScript?

A). 15

B). 105

C). NaN

D). Error

What will be the output of 20 / '5' in JavaScript?

A). 4

B). NaN

C). Infinity

D). Error

What will be the value of x after executing the code: let x = 5; x += '2';?

A). 7

B). '72'

C). 52

D). NaN

What will be the result of '10' + 10 in JavaScript?

A). '1010'

B). 20

C). NaN

D). Error

What will be the value of x after executing the code: let x = 10; x -= 2; x *= 3;?

A). 24

B). 30

C). 36

D). 12

What is the purpose of the % operator in JavaScript?

A). Exponentiation

B). Division

C). Modulus

D). Concatenation