// Create a function (you decide the name) that logs out the number 42
// to the console
// Call/invoke the function
function number(){
console.log(42)
}
number()
//result = 42
// we create a function by typing the keyword " function" + Function's name and ( we add the parameter here )
// {
// the function body
// }
// we call the function by typing it's name without the keyword and we add ()
function second (name){
name = "Elmustafa";
alert(name);
}
first();
function myFunc(p1, p2, pN)
{
// here "this" will equal "myThis"
}
let myThis = {};
// call myFunc using myThis as context.
// pass params to function arguments.
myFunc.call(myThis, "param1", "param2", "paramN");
const person = {
name: "John Smith",
getNameAndAddress: function(city, country)
{
return this.name+city+country;
}
}
const personWithoutGet = {
name: "Jerry Smithers"}
console.log(person.getNameAndAddress.call(personWithoutGet, 'Berlin','Germany'));
/*you can think of bind(), apply() and call() ALL as "stealing someone else's function to use."*/
/* victimBeingStolenFrom.functionName.call(theThief) */
/*notice the second variable personWithoutGet does not have a getName function*/