Operators in JavaScript

Length of a String

Get the number of characters in a string using.length:.


let name = "Avantika";
console.log(name.length);  // Output: 8

Substring

Extract part of a string with .substring():


let text = "Programming";
let subText = text.substring(0, 5);
console.log(subText);  // Output: Progr

Upper and Lower Case

Convert strings to upper or lower case:


let phrase = "Hello World!";
console.log(phrase.toUpperCase());  // Output: HELLO WORLD!
console.log(phrase.toLowerCase());  // Output: hello world!

Mathematical Expressions

Addition (+) Add two numbers:


let a = 5;
let b = 3;
console.log(a + b);

Subtraction (-) Subtract one number from another:


let a = 9;
let b = 4;
console.log(a - b);  // Output: 5

Multiplication (*) Multiply two numbers:


let a = 6;
let b = 7;
console.log(a * b);  // Output: 42

Division (/) Divide one number by another:


let a = 8;
let b = 2;
console.log(a / b);  // Output: 4

Boolean Expressions

Comparison Operators Compare two values:


let x = 10;
let y = 20;
console.log(x == y);  // Output: false
console.log(x < y);   // Output: true

Logical Operators Combine conditions:


let a = 5;
let b = 10;
console.log(a < b && b > a);  // Output: true