0% found this document useful (0 votes)
8 views2 pages

JavaScript Operators & Conditionals Guide

The document provides an overview of JavaScript operators, including arithmetic, comparison, and logical operators, along with examples. It also explains conditional statements such as if-else, switch statements, and the ternary operator, with illustrative examples. Additionally, it includes practice questions to reinforce understanding of these concepts.

Uploaded by

k4450992
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

JavaScript Operators & Conditionals Guide

The document provides an overview of JavaScript operators, including arithmetic, comparison, and logical operators, along with examples. It also explains conditional statements such as if-else, switch statements, and the ternary operator, with illustrative examples. Additionally, it includes practice questions to reinforce understanding of these concepts.

Uploaded by

k4450992
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript: Operators and Conditional Statements

1. JavaScript Operators

- Arithmetic Operators:

+ (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus), ** (Exponentiation)

Example: 2 + 3 = 5, 10 % 3 = 1

- Comparison Operators:

== (loose equal), === (strict equal), != (not equal), !== (strict not equal),

> (greater), < (less), >= (greater or equal), <= (less or equal)

Example: 5 == "5" is true, 5 === "5" is false

- Logical Operators:

&& (AND), || (OR), ! (NOT)

Example: true && false = false, true || false = true

2. Conditional Statements

- if, else if, else:

Allows branching logic based on conditions.

Example:

if (age < 18) {

[Link]("Minor");

} else if (age < 60) {

[Link]("Adult");

} else {

[Link]("Senior");

- switch statement:
Switches based on value of variable.

Example:

switch (day) {

case 1: [Link]("Monday"); break;

case 2: [Link]("Tuesday"); break;

default: [Link]("Other day");

- Ternary Operator:

Short syntax for if-else.

Example:

let result = age >= 18 ? "Adult" : "Minor";

Practice Questions
- Q1: Use if...else to check if a number is positive, negative, or zero.

- Q2: Use switch to print the day of the week (1 = Monday, ..., 7 = Sunday).

- Q3: Use comparison and logical operators to check if a user is between ages 18 and 25.

- Q4: Use a ternary operator to assign 'Pass' if marks >= 40, else 'Fail'.

- Q5: Write a program using if...else if...else to grade students (90+ A, 80+ B, etc.)

You might also like