JavaScript MCQ Javascript Data Types MCQ Question #4887
Single Choice Easy

QWhat is the result of the following code?
var num1 = 10;
var num2 = "20";
console.log(num1 + num2);

ID: #4887 Javascript Data Types MCQ 209 views
Question Info
#4887Q ID
EasyDifficulty
Javascript Data Types MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 30
  • B "30"
  • C "1020"
  • D TypeError
Correct Answer

Explanation

In JavaScript, the + operator can be used to add numbers or concatenate strings.
If both operands are numbers, the + operator will perform addition.
If either operand is a string, the + operator will treat both operands as strings and perform string concatenation.
In this case, the first operand (num1) is a number, but the second operand (num2) is a string.
Therefore, the + operator will treat both operands as strings and perform string concatenation, resulting in the string "1020".

Share This Question

Challenge a friend or share with your study group.