Q
What will be the output of the following JavaScript code? Code: let x = 15; if (x > 10) { console.log('x is greater than 10'); } else { console.log('x is not greater than 10'); }

Answer & Solution

Answer: Option A
Solution:
The output will be 'x is greater than 10' because the condition x > 10 is true, so the code inside the if block will execute, printing 'x is greater than 10' to the console.
Related Questions on Average

What does the following JavaScript code snippet do? Code: let x = 5; while (x > 0) { console.log(x); x -= 1; }

A). Prints even numbers from 5 to 1

B). Prints odd numbers from 5 to 1

C). Prints numbers from 5 to 0

D). Infinite loop

What will be the output of the following JavaScript code? Code: let i = 3; do { console.log(i); i--; } while (i > 0);

A). 3 2 1

B). 2 1 0

C). 3 2 1 0

D). 1 2 3

What is the purpose of the following JavaScript statement? let name = 'John';

A). Declare a function

B). Declare a variable

C). Print a message to the console

D). Loop through an array

What does the following JavaScript code snippet do? Code: let num = 5; while (num > 0) { console.log(num); num--; }

A). Declares a variable and assigns a value to it

B). Executes a block of code repeatedly until a condition becomes false

C). Calculates the sum of numbers from 1 to 5

D). Checks if a number is positive or negative

What will be the output of the following JavaScript code? Code: let i = 1; do { console.log(i); i++; } while (i < 3);

A). 1 2 3

B). 1 2 3 4

C). 2 3 4

D). Infinite loop

What is the purpose of the following JavaScript statement? let result = x > 0 ? 'Positive' : 'Non-positive';

A). Assigns the value 'Positive' to result if x is greater than 0, otherwise assigns 'Non-positive'

B). Checks if x is greater than 0

C). Prints 'Positive' if x is greater than 0, otherwise prints 'Non-positive'

D). None of the above

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

A). Finds the maximum number in the array numbers

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

C). Sums all numbers in the array numbers

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

What is the purpose of the following JavaScript statement? return result;

A). Exits the current loop or switch statement

B). Skips the current iteration in a loop

C). Exits the current function and returns a value

D). Continues to the next iteration in a loop

What will be the output of the following JavaScript code? Code: for (let i = 0; i <= 3; i++) { console.log(i); }

A). 0 1 2 3

B). 0 1 2

C). 1 2 3

D). 1 2 3 4

What will be the output of the following JavaScript code? Code: let count = 0; do { console.log(count); count++; } while (count < 3);

A). 0 1 2 3

B). 0 1 2

C). 1 2 3

D). Infinite loop