Multiple choice technology web technology

Which has no syntax error ?

  1. alert("hello "+3+" times);

  2. alert("hello "+3 times);

  3. alert("hello +3+ times");

  4. alert("hello "+3 +" times);

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The expression alert("hello +3+ times"); is a single valid string literal with no unescaped or unclosed quotes. The other options contain syntax errors because they have mismatched or unclosed double quotation marks inside the arguments.

AI explanation

To answer this question, we need to understand the syntax rules for JavaScript.

Option A) alert("hello "+3+" times); - This option has a syntax error. The closing parenthesis is missing at the end of the statement. The correct syntax should be alert("hello "+3+" times");.

Option B) alert("hello "+3 times); - This option also has a syntax error. The multiplication operator (*) is missing between the number 3 and the word "times". The correct syntax should be alert("hello "+3 * times); or alert("hello "+(3 * times)); depending on the value of the variable times.

Option C) alert("hello +3+ times"); - This option has no syntax error. It concatenates the string "hello ", the number 3, and the string " times" without any issues.

Option D) alert("hello "+3 +" times); - This option also has a syntax error. The closing parenthesis is missing at the end of the statement. The correct syntax should be alert("hello "+3 +" times");.

The correct answer is C. This option has no syntax error because it follows the correct syntax rules for concatenating strings and numbers in JavaScript.