Tutorialspoint

ES6 Assignment Operators Example

var num = 2 
if(num > 0) { 
   console.log(num + " is positive") 
} else if(num < 0) { 
   console.log(num + " is negative") 
} else { 
   console.log(num + " is neither positive nor negative") 
}

ES6 if-else Statement

var num = 12; 
if (num % 2 == 0) { 
   console.log("Even"); 
} else { 
   console.log("Odd"); 
}

ES6 Assignment Operators Example

var  num = 5 
if (num>0) { 
   console.log("number is positive") 
}

ES6 typeof operator

var num = 12 
console.log(typeof num); //output: number

ES6 Conditional Operator (?)

var num = -2 
var result = num > 0 ?"positive":"non-positive" 
console.log(result)

ES6 String Operators Concatenation operator

var msg = "hello"+"world" 
console.log(msg) 

ES6 Miscellaneous Operators

var x = 4 
var y = -x; 
console.log("value of x: ",x); //outputs 4 
console.log("value of y: ",y); //outputs -4

ES6 Assignment Operators Example

var a = 12; 
var b = 10; 
a = b;
console.log("a = b: " + a); 
a += b; 

console.log("a+=b: " + a); 
a -= b; 

console.log("a-=b: " + a); 
a *= b; 

console.log("a*=b: " + a); 
a /= b; 

console.log("a/=b: " + a); 
a %= b; 

console.log("a%=b: " + a);

ES6 Bitwise Operators Example

var a = 2; // Bit presentation 10 
var b = 3; // Bit presentation 11 
var result; 

result = (a & b); 
console.log("(a & b) => ", result); 

result = (a | b); 
console.log("(a | b) => ", result); 

result = (a ^ b); 
console.log("(a ^ b) => ", result); 

result = (~b); 
console.log("(~b) => ", result); 

result = (a << b); 
console.log("(a << b) => ", result); 

result = (a >> b); 
console.log("(a >> b) => ", result);

ES6 Logical Operators Example

var avg = 20; 
var percentage = 90; 

console.log("Value of avg: " + avg + " ,value of percentage: " + percentage); 
var res = ((avg > 50) && (percentage > 80)); 

console.log("(avg>50)&&(percentage>80): ", res); 
var res = ((avg > 50) || (percentage > 80)); 

console.log("(avg>50)||(percentage>l80): ", res); 
var res = !((avg > 50) && (percentage > 80)); 

console.log("!((avg>50)&&(percentage>80)): ", res);

Advertisements
Loading...