Wednesday, 21 September 2022

Arrow function

 hello = function() {

  return "Hello World!";

}



hello = () => {

  return "Hello World!";

}



hello = () => "Hello World!";


"If the function has only one statement, and the statement returns a value, you can remove the brackets and the return keyword"

"This works only if the function has only one statement."


hello = (val) => "Hello " + val;

If you have parameters, you pass them inside the parentheses


hello = val => "Hello " + val;

if you have only one parameter, you can skip the parentheses as well


No comments:

Post a Comment

ES6 Variables

  Block scope -  Block scoping means declaring a variable, not just inside a function, but around any curly brackets like if statements or ...