Tutorialspoint

ES6 RegExp exec()

var str = "Javascript is an interesting scripting language"; 
var re = new RegExp( "script", "g" ); 
var result = re.exec(str); 
console.log("Test 1 - returned value : " +  result);  
re = new RegExp( "pushing", "g" ); 
var result = re.exec(str); 
console.log("Test 2 - returned value : " +  result);

ES6 RegExp Prototype Sticky

var str = "Javascript is an interesting scripting language"; 
var re = new RegExp( "script", "g" ); 
re.test(str); 
console.log("Test 1 - Current Index: " +  re.lastIndex);  
re.test(str); 
console.log("Test 2 - Current Index: " + re.lastIndex) 

ES6 String Property Constructor

var str = new String( "This is string" ); 
console.log("str.constructor is:" + str.constructor)

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 let v/s var

var no = 10; 
var no = 20; 
console.log(no);

ES6 Let and Block Scope

"use strict" ;
function test() { 
   var num = 100;
   console.log("value of num in test() " + num); { 
      console.log("Inner Block begins") 
      let num = 200; 
      console.log("value of num : "+num)  
   } 
} 
test()

ES6 Custom Error with user-defined error message

function MyError(message) { 
   this.name = 'CustomError'; 
   this.message = message || 'Default Error Message';  
} try { 
   throw new MyError('Printing Custom Error message'); 
} 
catch (e) { 
   console.log(e.name);      
   console.log(e.message);  
}

ES6 Custom Error with default message

function MyError(message) { 
   this.name = 'CustomError'; 
   this.message = message || 'Error raised with default message'; 
} 
try { 
   throw new MyError(); 
} catch (e) {  
   console.log(e.name);      
   console.log(e.message);  // 'Default Message' 
}

ES6 Exception Handling

var a = 100; 
var b = 0; 
try { 
   if (b == 0 ) { 
      throw("Divide by zero error."); 
   } else { 
      var c = a / b; 
   } 
} 
catch( e ) { 
   console.log("Error: " + e ); 
}

ES6 Super Keyword

'use strict' 
class PrinterClass { 
   doPrint() {
      console.log("doPrint() from Parent called…") 
   } 
}  
class StringPrinter extends PrinterClass { 
   doPrint() { 
      super.doPrint() 
      console.log("doPrint() is printing a string…") 
   } 
} 
var obj = new StringPrinter() 
obj.doPrint()

1 2 3 4 5 6 7 ... 59 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.