Posts

Showing posts from April, 2023

ES6 Variables

Image
ES6 Variables     Now, with ES6, there are three keywords available to define variables: They provide different levels of scope to access the variable. Based on the requirement, you can define variables with these keywords and control its accessibility. var  let const   Using ES6 var Example var x = 9.9 ; If var declared outside a function, it belongs to the global scope. If var declared inside a function , it belongs to that function. If var declared inside the block, ex: in a for loop, the variable is still available outside that block. var has a function scope, not a block scope.   Using ES6  let Example   let x = 9.9 ; let is the block scoped version of var, and is limited to the block, where it is defined. If you use let inside a block, i.e. a for loop, the variable is only available inside that loop. let has a block scope. Using ES6 const Example const   y = 9.9 ;   y=10;   // It will result in an error     constant is a read only variable. Once it is initialized, it cannot b

ES6 Arrow Functions

Image
ES6 Arrow Functions   ES6HOME Arrow function in es6 anonymous function. It does not have any name and does not start with function keyword. Arrow function in ES6:   var arrowfun = () => { console.log( "Example Arrow Function" ); }; Optional parentheses for the single parameter var data = n => { console.log(n); } data( 10 ); Optional braces for single statement/parameter and the empty braces if there is no parameter to be passed. var display = () => console.log( "Hello World" );   display ();   Arrow function with multiple parameters: let sum = (a, b) => a + b; document .write(sum( 10 , 20 )); // Output 30 GO TOP Arrow function with default parameters: In ES6, parameters can initialize with some default values, if there is no value passed to it, or it is undefined. You can see the illustration for the same in the following code: For example var display = (a, b= 200 ) => { console.log(a + " " + b); } disp

ES6 Tutorial

Image
JavaScript ES6 Tutorial   What is ES6? ES6 known as ECMAScript6, It is advanced version o JavaScript, introduced to standardized JavaScript . It was published in 2015, that's the reason it is also called as ECMAScript2015. It is added some new features to JavaScript. Some popular features of the ECMAScript 6 are as follows… Classes Arrow Functions Variables (let, const, var) Array Functions Modules Destructuring Spread Operator   Popular ES6 frameworks such as ReactJS, AngularJS, and Vue.js implemented these features     ES6 Classes:   ES6 introduced classes. A class starts with a class keyword. Class contains constructor(). Inside, the constrictor properties are initialized.   class Person{ constructor(name) { this .pname = name; } } Create an object called "pobj" based on the Car class: const pobj = new Person( "John" );     demo.html    <!DOCTYPE html> <html> <body> <script> class Person{ constructor(name) {

Lambda expression in Java

Image
Learn Java Lambda expression     Lambda expression introduced in java8. It simplifies functional programming, and makes easier the development. Lambda expression is an anonymous or unnamed function. It is used to implement a method defined by a function interface. What is Functional Interface? If a Java interface contains one and only one abstract method, then it is called as functional interface. Difference between normal function and lambda. It is simple and readable.   Normal function looks as shown below void greet (){      System. out . println ( "Hello" ); } Using lambda expression, it can be written as: () → System.out.println("Hello");     // it is an anonymous function.   Defining the Lambda expression. The arrow operator  (->) used is known as an arrow operator or a lambda operator.  1. When there is a single parameter and single line, It can be written as shown   Syn:    parameterlist -> expression body   Ex:    () -> System. out . println