Arrow Functions In JavaScript

 

Arrow Functions In JavaScript 

arrow function is just the short foem of writing functions in js

short form
// Arrow function
    // let greet =  ()=> {
    //     console.log('Good morning');
    // }
in one line
let greet =  () => console.log('Good morning');

in short form
 // let sum2 = (a, b)=>{
    //     return a+b;
    // };

in one line
 let sum2 = (a, b) => a+b; 
    let half = a => a/2; 

using set time out with arrow function
greet();
    setTimeout(() => {
        console.log("We are inside settimeout");
    }, 3000);

this is complex (try later)
let obj1={
        greeting: "Good Morning",
        names: ["Harry", "Rohan", "SkillF", "DjKhiladi"],
        speak(){
            this.names.forEach((student)=>{
                console.log(this.greeting + " Kukdoo Koo " + student);
            });
        }
    }
    obj1.speak();









































Comments