var x = myFunction(10, 10); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
function world(params){
//Code to be executed when the function is called.
}
world()
//Explaination
//'world' in the function is the name of the function.
//There are brackets after function name. Those are use to push parameters
//The forth line Calls the function named 'world'
function walkTree(node) {
if (node === null) {
return;
}
// do something with node
for (let i = 0; i < node.childNodes.length; i++) {
walkTree(node.childNodes[i]);
}
}
// NOTE : Function defined using (Function CONSTRUCTOR) does not
// inherits any scope other than the GLOBAL SCOPE
var x=7;
function A(){
var x=70;
function B(){
console.log(x); // 70
}
let C = function(){
console.log(x); // 70
}
let D = new Function('console.log(x)'); // user caps F
B(); // 70
C(); // 70
D();// 7 - Inherits always the GLOBAL scope
};
A();
/*A function statement starts with the function keyword.
It can return a primitive type value, object, or another function.
For example, a function statement can return an object as shown in the following code example:*/
function getProduct(){
let product = {
Id:1,
Title:'Book',
Price: 30
};
return product;
}
let p1 = getProduct();
console.log(p1); // prints product object
//(don't type behind the// type function to after that name it//
function name() {
(name)=name
console.log(name)
};
//{ symbol is used o group together code but you must create n index/array of 2(array3)//
//! Button Click Event
//! regular function
document.querySelector("button").addEventListener('click', handlClick);
function handlClick() {
alert("I got clicked!")//just to show it works
//what to do when click detected
}
//!anonymous function
document.querySelector("button").addEventListener('click',function handlClick() {
alert("I got clicked!")//just to show it works
//what to do when click detected
});