//
to comment out a single line of code.
// This is a single-line comment
let x = 10; // This is also a comment
/* ... */
to comment out multiple lines of code.
/*
This is a
multi-line comment
*/
let y = 20;
Operators are symbols that perform operations on variables and values.
Types of Operators:
let a = 10;
let b = 5;
console.log(a + b); // Addition: 15
console.log(a - b); // Subtraction: 5
console.log(a * b); // Multiplication: 50
console.log(a / b); // Division: 2
console.log(a % b); // Modulus: 0 (remainder)
let x = 10; // Assign 10 to x
x += 5; // x = x + 5 (x becomes 15)
x -= 2; // x = x - 2 (x becomes 13)
let a = 10;
let b = 20;
console.log(a == b); // Equal to: false
console.log(a != b); // Not equal to: true
console.log(a > b); // Greater than: false
console.log(a < b); // Less than: true
let a = 10;
let b = 20;
console.log(a > 5 && b > 15); // Logical AND: true
console.log(a > 15 || b > 15); // Logical OR: true
console.log(!(a > 15)); // Logical NOT: true
let count = 5;
count++; // Increment: count becomes 6
count--; // Decrement: count becomes 5
let age = 18;
let result = (age >= 18) ? "Adult" : "Minor";
console.log(result); // Output: "Adult"
Conditional statements are used to perform different actions based on different conditions.
if
Statement:
let age = 18;
if (age >= 18) {
console.log("You are eligible to vote.");
}
if-else
Statement:
let age = 16;
if (age >= 18) {
console.log("You are eligible to vote.");
} else {
console.log("You are not eligible to vote.");
}
if-else if-else
Statement:
let marks = 85;
if (marks >= 90) {
console.log("Grade A");
} else if (marks >= 75) {
console.log("Grade B");
} else if (marks >= 50) {
console.log("Grade C");
} else {
console.log("Fail");
}