|
| 1 | +// Assignment operator = |
| 2 | +var num1 = 10; |
| 3 | +console.log("num1 : " + num1); |
| 4 | + |
| 5 | +// Arithmetic operators + - * / |
| 6 | +var a = 10; |
| 7 | +var b = 20; |
| 8 | +var sum = a + b; |
| 9 | +console.log("a + b : " + sum); |
| 10 | + |
| 11 | +var mul = a * b; |
| 12 | +console.log("a * b : " + mul); |
| 13 | + |
| 14 | +// Short hand math += , -= , *= , /= |
| 15 | +a = 10; |
| 16 | +b = 20; |
| 17 | +var add = 0; |
| 18 | +add = add + (a + b); // long way |
| 19 | +add += (a + b); // short hand math |
| 20 | + |
| 21 | +console.log('add : ' + add); |
| 22 | + |
| 23 | +// Conditional operators < , > , <= , >= , != |
| 24 | +var age = 25; |
| 25 | +if(age <= 18){ |
| 26 | + console.log("Your are Minor"); |
| 27 | +} |
| 28 | +else{ |
| 29 | + console.log("You are Major"); |
| 30 | +} |
| 31 | + |
| 32 | +// Unary Operator ++ , -- (pre , post) |
| 33 | +var x = 10; |
| 34 | +x = x + 1; //11 |
| 35 | +x += 1; // 12 |
| 36 | +x++; // 13 |
| 37 | +console.log('x : ' + x); // 13 |
| 38 | + |
| 39 | +// Logical operators AND , OR |
| 40 | +var inRelation = true; |
| 41 | +var parentsAgreed = false; |
| 42 | +if(inRelation && parentsAgreed){ |
| 43 | + console.log("Get Marry Soon"); |
| 44 | +} |
| 45 | +else{ |
| 46 | + console.log("Wait until parents agreed"); |
| 47 | +} |
| 48 | + |
| 49 | +// String Concatenation Operator |
| 50 | +var str = "10" + 10 + 10 + 10; |
| 51 | +console.log('str : ' + str); |
| 52 | + |
| 53 | +// Ternary operator (? :) |
| 54 | +age = 25; |
| 55 | + |
| 56 | +(age <= 18) ? console.log("You are Minor") : console.log("You are Major"); |
| 57 | + |
| 58 | +// Type of operator |
| 59 | +var abc; |
| 60 | +console.log('value : ' + abc + ' Data Type :' + typeof abc); |
| 61 | + |
| 62 | +abc = 10; |
| 63 | +console.log('value : ' + abc + ' Data Type :' + typeof abc); |
| 64 | + |
| 65 | +abc = 'test'; |
| 66 | +console.log('value : ' + abc + ' Data Type :' + typeof abc); |
| 67 | + |
| 68 | +abc = true; |
| 69 | +console.log('value : ' + abc + ' Data Type :' + typeof abc); |
| 70 | + |
| 71 | +abc = null; |
| 72 | +console.log('value : ' + abc + ' Data Type :' + typeof abc); |
| 73 | + |
| 74 | +// == operator |
| 75 | +a = 10; |
| 76 | +b = "10"; |
| 77 | +if(a == b){ |
| 78 | + console.log("Both are Equal"); |
| 79 | +} |
| 80 | +else{ |
| 81 | + console.log("Both are NOT EQUAL") |
| 82 | +} |
| 83 | + |
| 84 | +// === operator |
| 85 | +a = 10; |
| 86 | +b = "10"; |
| 87 | +if(a === b){ |
| 88 | + console.log("Both are Equal"); |
| 89 | +} |
| 90 | +else{ |
| 91 | + console.log("Both are NOT EQUAL") |
| 92 | +} |
0 commit comments