JS Operators
In this page:
result = operand1 operator operand2;
Arithmetic Operators
Arithmetic operators संख्याओं पर गणितीय गणनाएँ करते हैं, जिनमें जोड़, घटाव, गुणा, भाग, और शेषफल तथा exponentiation जैसे ज़्यादा विशिष्ट operations शामिल हैं।
उदाहरण: Arithmetic Operators
// Print `10 + 3` to the console
// Print `10 + 3` to the console
console.log(10 + 3);
// Print `10 % 3` to the console
// Print `10 % 3` to the console
console.log(10 % 3);
// Print `2 ** 3` to the console
// Print `2 ** 3` to the console
console.log(2 ** 3);
Comparison Operators
Comparison operators दो values की तुलना करते हैं और boolean नतीजा, true या false, देते हैं, जिनमें बराबर, बराबर नहीं, बड़ा और छोटा शामिल हैं, साथ ही सख्त संस्करण जो type भी जाँचते हैं।
उदाहरण: Comparison Operators
// Print `5 == "5"` to the console
// Print `5 == "5"` to the console
console.log(5 == "5");
// Print `5 === "5"` to the console
// Print `5 === "5"` to the console
console.log(5 === "5");
// Print `5 > 3` to the console
// Print `5 > 3` to the console
console.log(5 > 3);
Logical Operators
Logical operators boolean values को जोड़ते या उलटते हैं, && (और) के लिए दोनों पक्षों का true होना ज़रूरी है, || (या) के लिए कम से कम एक पक्ष का true होना, और ! (नहीं) किसी boolean के value को पूरी तरह पलट देता है।
उदाहरण: Logical Operators
// Print `true && false` to the console
// Print `true && false` to the console
console.log(true && false);
// Print `true || false` to the console
// Print `true || false` to the console
console.log(true || false);
// Print `!true` to the console
// Print `!true` to the console
console.log(!true);
Assignment और Ternary Operators
Assignment operator = किसी variable में value रखता है, और JavaScript एक संक्षिप्त ternary operator भी देती है, condition ? valueIfTrue : valueIfFalse, जो value बनाने वाले सरल if/else के शॉर्टहैंड के रूप में है।
उदाहरण: Assignment and Ternary Operators
// Declare the variable `age`, set to `20`
// Declare the variable `age`, set to `20`
let age = 20;
// Declare the variable `status`, set to `age >= 18 ? "adult" : "minor"`
// Declare the variable `status`, set to `age >= 18 ? "adult" : "minor"`
let status = age >= 18 ? "adult" : "minor";
// Print `status` to the console
// Print `status` to the console
console.log(status);
typeof और Spread Operators
typeof किसी value का type बताने वाली string लौटाता है, जो यह जाँचने में उपयोगी है कि आप किस तरह के data के साथ काम कर रहे हैं, जबकि spread operator ... किसी array या object के elements को अलग-अलग फैला देता है, जो आमतौर पर collections की नक़ल बनाने या उन्हें जोड़ने के लिए इस्तेमाल होता है।
उदाहरण: typeof and Spread Operators
// Print `typeof "hello"` to the console
// Print `typeof "hello"` to the console
console.log(typeof "hello");
// Print `typeof null` to the console
// Print `typeof null` to the console
console.log(typeof null);
// Declare the constant `nums`, set to `[1, 2, 3]`
// Declare the constant `nums`, set to `[1, 2, 3]`
const nums = [1, 2, 3];
// Print `[...nums, 4, 5]` to the console
// Print `[...nums, 4, 5]` to the console
console.log([...nums, 4, 5]);
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: