JavaScript Operators: Easy Guide for Beginners

JavaScript ????????? operators ?????? expressions calculations, comparisons, ?????? logical decisions ?????? ????????? core building blocks ???????????? ?????? ??????????????? arithmetic, comparison, logical, ?????? assignment operators ?????? ??????????????? ?????? ????????? ???????????? ??????, ????????? ?????? operator precedence ?????? grouping ?????? ?????????????????? ????????? Extra theory, practical exercise (BMI calculator), quiz, ?????? operator precedence diagram ?????? ????????? ?????? JavaScript ????????? ?????? confident ?????? ?????????????????????

JavaScript ????????? ???????????????????????? ???????????? ???????????? ?????????? - What is Operators in JavaScript in Hindi?

Operators values ?????? operations perform ???????????? ?????????, ?????? expressions operators ?????? operands ?????? combination ????????? ?????? ?????? value produce ???????????? ???????????? ??????????????????: 5 + 3 ?????? expression ?????? ?????? 8 ???????????? ?????????

Theoretical Foundation

  • Operands: Operators ????????? values ?????? ????????? ???????????? ????????? (???????????? 5, 3)???

  • Types of Operators: Unary (?????? operand, ???????????? !true), Binary (?????? operands, ???????????? 5 + 3), Ternary (????????? operands, ???????????? condition ? expr1 : expr2)???

  • Evaluation: JavaScript expressions ?????? left-to-right evaluate ???????????? ??????, ??????????????? precedence ?????? associativity rules apply ???????????? ????????????

  • Side Effects: ????????? operators (???????????? = ?????? +=) variables ?????? state ??????????????? ?????????, ???????????? side effect ???????????? ????????????

JavaScript ????????? ?????????????????? ?????? ?????????????????? - Types of Operators in JavaScript in Hindi

1. Arithmetic Operators

Arithmetic operators mathematical calculations ?????? ????????? ????????????

  • + (Addition): ?????? values ?????????????????? ?????????

    let sum = 10 + 5; // 15
  • - (Subtraction): ???????????????

    let diff = 10 - 5; // 5
  • * (Multiplication): ???????????????

    let product = 10 * 5; // 50
  • / (Division): ????????????

    let quotient = 10 / 5; // 2
  • % (Modulus): Remainder ???????????? ?????????

    let remainder = 10 % 3; // 1
  • ** (Exponentiation): Power calculate ???????????? ?????????

    let power = 2 ** 3; // 8

Additional Theory:

  • Floating-Point Precision: JavaScript numbers IEEE 754 standard follow ???????????? ?????????, ??????????????? decimal calculations ????????? precision issues ?????? ???????????? ????????? (???????????? 0.1 + 0.2 !== 0.3)??? Solution: toFixed() ?????? libraries ???????????? Big.js???

  • Modulus with Negatives: % operator dividend ?????? sign preserve ???????????? ????????? ??????????????????: -10 % 3 = -1, ????????????????????? -10 = (-3 * 3) - 1???

  • Use Cases: Arithmetic operators loops, counters, ?????? calculations (???????????? physics simulations, financial apps) ????????? common ????????????

2. Comparison Operators

Comparison operators ?????? values ?????? ??????????????? ???????????? ????????? ?????? Boolean (true/false) return ???????????? ????????????

  • == (Loose Equality): Values ?????? ???????????????, type coercion ?????? ????????????

    console.log(5 == "5"); // true
  • === (Strict Equality): Value ?????? type ??????????????? ????????? ???????????? ?????????

    console.log(5 === "5"); // false
  • != (Loose Inequality): Values ????????? ????????????, type coercion ?????? ????????????

    console.log(5 != "5"); // false
  • !== (Strict Inequality): Value ?????? type ????????? ???????????????

    console.log(5 !== "5"); // true
  • >, <, >=, <=: Greater than, less than, ????????????

    console.log(10 > 5); // true

Additional Theory:

  • Type Coercion Risks: == string ?????? number ?????? number ?????? string ????????? convert ?????? ???????????? ??????, ??????????????? bugs ?????? ???????????? ???????????? ??????????????? === ???????????? ???????????????

  • String Comparisons: Strings ?????? ASCII/Unicode order ????????? compare ???????????? ???????????? ?????? (???????????? "apple" < "banana" ??? true)???

  • Edge Cases: NaN ???????????? ?????? value (????????? ?????? ??????) equal ???????????? ??????????????? NaN == NaN ??? false??? isNaN() ???????????? ???????????????

    console.log(isNaN(10 / "text")); // true

3. Logical Operators

Logical operators conditions ?????? combine ???????????? ????????????

  • && (AND): ??????????????? conditions true ???????????? ?????? true???

    let isAdult = 20 > 18 && true; // true
  • || (OR): ????????? ?????? condition true ???????????? ?????? true???

    let hasAccess = false || true; // true
  • ! (NOT): Condition ?????? invert ???????????? ?????????

    let isFalse = !true; // false

Additional Theory:

  • Short-Circuiting: && ????????? ???????????? condition false ?????? ?????? ??????????????? evaluate ???????????? ????????????; || ????????? ???????????? true ?????? ?????? ??????????????? skip ???????????? ????????? Performance optimization ?????? ????????? useful???

    let result = false && expensiveFunction(); // expensiveFunction() ???????????? ???????????????
  • Truthy/Falsy Values: Non-boolean values ?????? logical operators truthy/falsy rules follow ???????????? ???????????? Falsy values: 0, "", null, undefined, NaN, false???

    console.log(0 || "Hello"); // "Hello" (0 is falsy)
  • Use Cases: Logical operators form validation, access control, ?????? conditional rendering ????????? ???????????? ???????????? ????????????

4. Assignment Operators

Assignment operator's variables ?????? values assign ???????????? ????????????

  • = (Assign): Value assign ???????????? ?????????

    let x = 10;
  • +=, -=, *=, /=, ?????????: Operation ?????? assignment combine ???????????? ????????????

    let y = 5;
    y += 3; // y = y + 3; // 8

Additional Theory:

  • Associativity: Assignment operators right-to-left evaluate ???????????? ?????????, ??????????????? chaining possible ?????????

    let a, b;
    a = b = 10; // a = 10, b = 10
  • Performance: Compound assignment operators (+=, ?????????) single operation ????????? calculation ?????? assignment ???????????? ?????????, ?????? memory-efficient ?????????

  • Edge Case: Objects ?????? ?????????, = shallow copy ??????????????? ??????, ??????????????? reference issues ?????? ???????????? ????????????

    let obj1 = { x: 10 };
    let obj2 = obj1;
    obj2.x = 20; // obj1.x ?????? 20 ?????? ???????????? ??????

5. Operator Precedence ?????? Grouping

  • Precedence: Operators ?????? execution order ??????????????????????????? ???????????? ????????? ??????????????????:

    • *, / ?????? precedence +, - ?????? ?????????????????? ?????????

    • ??????????????????: 5 + 3 * 2 = 11 (????????????????????? * ???????????? evaluate ???????????? ??????)???

  • Grouping: Parentheses () precedence ?????? override ???????????? ????????????

    let result = (5 + 3) * 2; // 16

Additional Theory:

  • Precedence Table: MDN ?????? Operator Precedence ?????????????????? Highest precedence: () ?????? member access (.), lowest: ,.

  • Associativity: Same precedence ???????????? operators left-to-right (???????????? +, -) ?????? right-to-left (???????????? =, **) evaluate ???????????? ????????????

    let x = 2 ** 3 ** 2; // right-to-left: 2 ** (3 ** 2) = 2 ** 9 = 512
  • Best Practice: Complex expressions ????????? ??????????????? parentheses ???????????? ???????????? readability ?????? predictability ?????? ????????????

  • Common Pitfall: Precedence ignorance ?????? bugs??? ??????????????????: true || false && false ????????? && ???????????? evaluate ???????????? ?????????

    console.log(true || false && false); // true (&& ????????????, ????????? ||)

Visual: Operator Precedence Diagram

[caption id="attachment_4963" align="aligncenter" width="1280"]Operators Precedence Diagram ?????? diagram operator precedence ?????? visually ????????????????????? ????????? Highest precedence (???????????? *, /, **) ????????? ?????????, lowest (???????????? +, -, =) ??????????????? Parentheses precedence ?????? override ???????????? ????????????[/caption]

Practical Exercise: BMI Calculator

Task: ?????? program ??????????????? ?????? user ?????? weight (kg) ?????? height (m) ?????? ?????? BMI (Body Mass Index) calculate ????????????

  • Formula: BMI = weight / (height * height)

  • Input: prompt ?????? weight ?????? height ????????????

  • Output: BMI ?????? console ????????? ?????????????????? ???????????????

Code:

let weight = parseFloat(prompt("Enter weight in kg:"));
let height = parseFloat(prompt("Enter height in meters:"));
let bmi = weight / (height * height);
console.log(`Your BMI is: ${bmi.toFixed(2)}`);

Theoretical Notes:

  • parseFloat string input ?????? number ????????? convert ???????????? ?????????

  • height * height ????????? multiplication ?????? precedence division ?????? ?????????????????? ??????, ??????????????? parentheses clarity ?????? ????????? optional ????????????

  • toFixed(2) decimals ?????? 2 places ?????? limit ???????????? ?????????

  • Edge Case: Invalid input (???????????? non-numeric) ?????? NaN ?????? ???????????? ????????? Input validation add ???????????????

    if (isNaN(weight) || isNaN(height)) {
      console.log("Please enter valid numbers");
    }

Run: Browser ????????? HTML ???????????? ??????????????? ?????? ??????????????? ???????????????

Quiz: Operator Outputs

???????????? 5 multiple-choice ???????????? ?????????:

  1. 5 + 3 * 2 ?????? output ???????????? ???????

    • A) 16

    • B) 11

    • C) 10

    • D) 8

    • Answer: B) 11

  2. 5 == "5" ?????? result ???????????? ???????

    • A) true

    • B) false

    • C) undefined

    • D) null

    • Answer: A) true

  3. true && false ?????? output ???????????? ???????

    • A) true

    • B) false

    • C) null

    • D) undefined

    • Answer: B) false

  4. x = 5; x += 3; ?????? ????????? x ?????? value ???????????? ?????????????

    • A) 5

    • B) 3

    • C) 8

    • D) 15

    • Answer: C) 8

  5. 2 ** 3 ** 2 ?????? output ???????????? ???????

    • A) 64

    • B) 512

    • C) 9

    • D) 16

    • Answer: B) 512

Conclusion

?????? ??????????????? ????????? ???????????? JavaScript ?????? operators (arithmetic, comparison, logical, assignment) ?????? expressions ?????? ??????????????? ?????? ??????????????? Precedence, associativity, ?????? type coercion ???????????? theoretical concepts ?????? foundation ??????????????? BMI calculator exercise ?????? quiz ?????? practical skills ?????? reinforce ??????????????? ???????????? ????????????????????? ????????? ?????? control flow (if-else, loops) explore ????????????????????? Practice ???????????? ?????? ???????????? ???????????????!

Also Read:??

Latestor
Home Menu Login

Share to other apps

Report Content

Why are you reporting this content?

Your selection helps us review the content and take appropriate action.

Hate & Discrimination
Content that spreads hate or unfair treatment against a person or group because of who they are.
Abuse & Harassment
Content that insults, threatens, bullies, or makes someone uncomfortable.
Violence & Threats
Content that talks about hurting people, animals, or property, or supports violence.
Child Safety
Any content that harms, exploits, or puts children at risk.
Privacy Violation
Sharing someone’s personal information or photos without permission.
Illegal & Regulated Activities
Content that promotes or helps with illegal activities like drugs, weapons, or trafficking.
Spam & Misleading Content
Fake, misleading, or repeated content meant to trick users.
Suicide or Self-Harm
Content that encourages or explains self-harm or suicide.
Sensitive or Disturbing Content
Shocking or graphic content that may upset users.
Impersonation
Pretending to be another person or organization.
Extremism & Hate Groups
Content that supports violent groups or hateful ideas.
Civic Integrity
Content that spreads false information about elections or public processes.