menu

JavaScript Conditional Statements

JavaScript Conditional Statements - Important Points


6. Which of the following is not a valid way to declare a variable in JavaScript?

A. var x;

B. let x;

C. const x;

D. int x;

Discuss Work Space

Answer: option d

Explanation:

int is not a valid keyword for declaring variables in JavaScript. The correct keywords are var, let, and const.

7. What is the purpose of the switch statement in JavaScript?

A. To declare a new variable

B. To define a loop

C. To execute a block of code based on a condition

D. To assign a value to a variable

Discuss Work Space

Answer: option c

Explanation:

The switch statement is used to execute a block of code based on a condition. It is often used as an alternative to a series of if statements.

8. What is the purpose of the ternary operator in JavaScript?

A. To declare a new variable

B. To define a loop

C. To execute a block of code based on a condition

D. To assign a value to a variable

Discuss Work Space

Answer: option c

Explanation:

The ternary operator is used to execute a block of code based on a condition. It is often used as an alternative to an if statement.

9. Which of the following is the correct syntax for a ternary operator in JavaScript?

A. condition ? true : false;

B. true : false ? condition;

C. true ? condition : false;

D. condition : true ? false;

Discuss Work Space

Answer: option a

Explanation:

The correct syntax for a ternary operator in JavaScript is condition ? true : false;. The condition is evaluated, and if it is true, the code block after the ? symbol is executeIf it is false, the code block after the : symbol is executed.

10. What is the syntax of the if statement in JavaScript?

A. if (condition) {code block}

B. if {code block} (condition)

C. (condition) if {code block}

D. {code block} if (condition)

Discuss Work Space

Answer: option a

Explanation:

The if statement in JavaScript starts with the keyword 'if' followed by a condition in parentheses, and then a code block enclosed in curly braces.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now