This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To invoke the function,i will call its name (addNumbers) and give it 2 parameters | |
addNumbers(5,2); // will output : 7 | |
addNumbers(100,1); // will output : 101 | |
//A simple function declaration named addNumbers that accepts 2 input parameters | |
function addNumbers(num1,num2) { | |
let sum = num1 + num2; | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A simple function declaration named printName that accepts username as an input parameter | |
function printName(username) { | |
return "Your name is : " + username; | |
} | |
//To invoke the function , i will call its name (printName) and give it a parameter e.g "Simba" | |
// or "David" or "Mary" etc , try it and use your own name! | |
printName("Simba"); // will output : "Your name is : Simba" | |
printName("David"); // will output : "Your name is : David" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A simple function expression named userName that accepts username as an input parameter | |
const userName = function printName(username) { | |
return "Your name is : " + username; | |
} | |
//To invoke the function , i will call its name (userName) and give it a parameter e.g "Simba" | |
// or "David" or "Mary" etc , try it and use your own name! | |
userName("Simba"); // will output : "Your name is : Simba" | |
userName("David"); // will output : "Your name is : David" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To invoke the function,i will try call its name (addNumbers) and give it 2 parameters | |
addNumbers(5,2); // Uncaught ReferenceError: addNumbers is not defined | |
addNumbers(100,1); // Uncaught ReferenceError: addNumbers is not defined | |
//A simple function expression named addNumbers that accepts 2 input parameters | |
const addNumbers = function addTwoNumbers(num1,num2){ | |
let sum = num1 + num2; | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//An anonymous function expression that accepts a single parameter (username) | |
const printName = function (username){ | |
return "Your name is : " + username; | |
} | |
//To invoke the function,i will call printName and give it a parameter e.g "Simba" | |
// or "David" or "Mary" etc , try it and use your own name! | |
printName("Simba"); // will output : "Your name is : Simba" | |
printName("David"); // will output : "Your name is : David" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//An ES6 Arrow function named addNumbers that accepts 2 input parameters | |
const addNumbers = (num1,num2) =>{ | |
let sum = num1 + num2; | |
return sum; | |
} | |
//To invoke the function,i will call its name (addNumbers) and give it 2 parameters | |
addNumbers(5,2); // will output : 7 | |
addNumbers(100,1); // will output : 101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//An ES6 Arrow function named addNumbers that accepts 2 input parameters | |
const addNumbers = (num1,num2) => { | |
let sum = num1 + num2; | |
return sum; | |
} | |
//To invoke the function,i will call its name (addNumbers) and give it 2 parameters | |
addNumbers(5,2); // will output : 7 | |
addNumbers(100,1); // will output : 101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Arrow function that takes any number as input | |
//adds 100 and returns the total | |
const addHundred = num => num + 100; | |
addHundred(1);//output : 101 | |
addHundred(1000); //output : 1100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Arrow function that uses an implicit return | |
const addNumbers = (num1,num2) => num1 + num2; | |
addNumbers(10,20); // 30 | |
//Arrow function that uses a 'return' keyword in the block body | |
const addSomeNumbers = (num1,num2) => { | |
let total = num1 + num2; | |
return total; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//syntax for creating an IIFE | |
(function () { | |
//functions statements go here | |
})(); |
OlderNewer