JS Arithmetic
result = a + b; // also -, *, /, %, **
x++;
x--;
मुख्य Operators
JavaScript के पाँच बुनियादी arithmetic operators हैं: जोड़ के लिए +, घटाव के लिए -, गुणा के लिए *, भाग के लिए /, और शेषफल के लिए %, जिसे कभी-कभी modulo कहा जाता है।
उदाहरण: The Core 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 `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 `10 % 3` to the console
// Print `10 % 3` to the console
console.log(10 % 3);
Exponentiation
** operator किसी संख्या को दूसरी संख्या की घात तक बढ़ाता है, और रोज़मर्रा की अधिकांश घात गणनाओं के लिए पुराने, ज़्यादा शब्दबहुल Math.pow() function की जगह लेता है।
उदाहरण: Exponentiation
console.log(2 ** 3);
console.log(Math.pow(2, 3));
Increment और Decrement
++ किसी variable के value को एक से बढ़ाता है, और -- एक से घटाता है, दोनों एक pre रूप (++x) में उपलब्ध हैं जो value को इस्तेमाल होने से पहले बदलता है, और एक post रूप (x++) में जो पहले मूल value इस्तेमाल करता है।
उदाहरण: Increment and Decrement
let x = 5;
console.log(++x); // 6, pre-increment
let y = 5;
console.log(y++); // 5, post-increment
console.log(y); // 6
Operator Precedence
JavaScript गणित का मानक क्रम अपनाती है, गुणा, भाग और शेषफल जोड़ और घटाव से पहले होते हैं, और किसी विशिष्ट evaluation क्रम को लागू करने के लिए parentheses का हमेशा इस्तेमाल किया जा सकता है।
उदाहरण: Operator Precedence
console.log(2 + 3 * 4); // 14, multiplication first
console.log((2 + 3) * 4); // 20, parentheses force order
Math Object
Built-in Math object बुनियादी operators से आगे कई उपयोगी numeric functions देता है, जिनमें Math.round(), Math.max(), Math.min() और Math.sqrt() शामिल हैं, जिन्हें एक बाद के अध्याय में ज़्यादा विस्तार से बताया गया है।
उदाहरण: The Math Object
// Print `Math.round(4.7)` to the console
// Print `Math.round(4.7)` to the console
console.log(Math.round(4.7));
// Print `Math.max(3, 7, 2)` to the console
// Print `Math.max(3, 7, 2)` to the console
console.log(Math.max(3, 7, 2));
// Print `Math.min(3, 7, 2)` to the console
// Print `Math.min(3, 7, 2)` to the console
console.log(Math.min(3, 7, 2));
// Print `Math.sqrt(16)` to the console
// Print `Math.sqrt(16)` to the console
console.log(Math.sqrt(16));
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: