syntax 1:
let name = () => "Hello World";
syntax 2:
let name = (a) => 'Hello ${a}';
syntax 3:
let name = (a, b) => {
return '${a} ${b}';
};
Arrow functions works like function expression. For example in the syntax 1:
let name = function(){ return "Hello World"; };
In the right side of the arrow, is the statement you want to perform. If it is just one line code, there is no need to use a brace but if it is a multi line, you need a brace like in syntax 3 and you need a return statement for that.
================
let globalVariable = (param1) => 'From Mars ${param1}';
function connectingWorlds(){
document.write(globalVariable("to Earth"));
}
================
HTML
connectingWorlds()
Result:
From Mars to Earth
Please take note of the globalVariable, the argument was put inside its parenthesis during invocation of the arrow function. If you just write:
globalVariable(), the Result would be: From Mars undefined
globalVariable, the Result would be: (param1) => 'From Mars ${param1}';
YOU ARE READING
Javascript Programming
RandomI am just documenting things what i learned online in here. I do express things in my own words. And I create my own program samples which serves as my practice. I do this so that when someday I would need some notes to review, I can just visit in h...
