$100 Website Offer

Get your personal website + domain for just $100.

Limited Time Offer!

Claim Your Website Now

JavaScript Operators

JavaScript supports a variety of operators, which are symbols used to perform operations on variables and values. Here’s an overview of some common types of operators in JavaScript:

1. Arithmetic Operators:

let x = 10;
let y = 5;

console.log(x + y); // Addition: 15
console.log(x - y); // Subtraction: 5
console.log(x * y); // Multiplication: 50
console.log(x / y); // Division: 2
console.log(x % y); // Modulus: 0 (remainder after division)
console.log(x ** y); // Exponentiation: 100000

2. Assignment Operators:

let a = 10;

a += 5; // Equivalent to a = a + 5
console.log(a); // Output: 15

a -= 3; // Equivalent to a = a - 3
console.log(a); // Output: 12

a *= 2; // Equivalent to a = a * 2
console.log(a); // Output: 24

a /= 4; // Equivalent to a = a / 4
console.log(a); // Output: 6

3. Comparison Operators:

let p = 5;
let q = "5";

console.log(p == q); // Equality (loose equality): true
console.log(p === q); // Strict equality (checks value and type): false
console.log(p != q); // Inequality (loose inequality): false
console.log(p !== q); // Strict inequality: true

console.log(x > y); // Greater than: true
console.log(x < y); // Less than: false
console.log(x >= y); // Greater than or equal to: true
console.log(x <= y); // Less than or equal to: false

4. Logical Operators:

let isTrue = true;
let isFalse = false;

console.log(isTrue && isFalse); // Logical AND: false
console.log(isTrue || isFalse); // Logical OR: true
console.log(!isTrue); // Logical NOT: false

5. Unary Operators:

let num = 5;

console.log(-num); // Unary negation: -5
console.log(+num); // Unary plus: 5 (no effect)
console.log(++num); // Increment: 6
console.log(--num); // Decrement: 5

6. Conditional (Ternary) Operator:

let age = 20;
let eligibility = (age >= 18) ? "Eligible" : "Not eligible";
console.log(eligibility); // Output: "Eligible"

These are some of the fundamental operators in JavaScript. They allow you to perform a wide range of operations, from basic arithmetic to complex conditional logic. Understanding and using these operators is essential for writing effective and concise JavaScript code.

Related Posts

Global Mobile Network Identifiers: A Practical Guide to Telecom Codes and Provider Records

Introduction Every time a mobile phone connects to a cellular tower, a quiet digital handshake takes place. Whether a smartphone is roaming in a foreign airport, an…

Read More

Optimizing Reservations, Waitlists, and Walk-Ins for Independent Dining Rooms

Introduction Running a busy dining room requires careful coordination between the front-of-house staff, the kitchen team, and arriving guests. When a restaurant relies on paper books or…

Read More

Turning Clicks into Clients: The Power of Effective Service Pages

Introduction Driving traffic to a business website is only half the battle. Many business owners invest heavily in digital marketing, social media, and search engine optimization, only…

Read More

The Importance of the About Us Page in Building Online Trust

Introduction When potential customers land on a business website for the very first time, they are looking for more than just products or services. They are looking…

Read More

Shaping Customer Perception Through Effective Homepage Design

Introduction When potential customers visit a business website for the very first time, the homepage serves as the virtual storefront. Within moments of landing on the page,…

Read More

Exploring Colombia on Two Wheels: Medellín, Bogotá, Cartagena, and Beyond

Introduction — Discover Colombia with MotoShare.co Colombia is a land of striking geographical contrasts. Within its borders, modern urban skylines give way to towering Andean passes, lush…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x