Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js create and call function

// 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
Comment

how to call a function in JavaScript

// calling our function
displayGreeting();
Comment

how to call a function javascript

//  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();
Comment

javascript call

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");
Comment

JavaScript Function call()

const person = {
  firstName:"John",
  lastName: "Doe",
  fullName: function () {
    return this.firstName + " " + this.lastName;
  }
}

// This will return "John Doe":
person.fullName();  
Comment

javascript call()

const personOne = {
  firstName : "Elon",
  secondName : "Musk"
}

const getFullName = function(company, country) {
  console.log(this.firstName + " " + this.secondName + ", " + company + ", " + country);
}

const personTwo = {
  firstName : "Mark",
  secondName : "Zuckerburg"
}

getFullName.call(personOne, "Tesla", "United States");    // outputs Elon Musk, Tesla, United States
getFullName.call(personTwo, "Facebook", "United States");    // outputs Mark Zuckerberg, Facebook, United States
Comment

The JavaScript call() Method


		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*/
Comment

javascript call example

l = "abcder";
q = "Ererwrwrewrew";
console.log(String.prototype.substr.call(q, 1, 4))
/*rerw...4 refers to how many characters to substring*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: resolvers in angular 
Javascript :: Material-ui account icon 
Javascript :: factory function in javascript 
Javascript :: javascript syntax of throw statement 
Javascript :: add new field using update in mongoose 
Javascript :: discord.js vs discord.py 
Javascript :: how to add a new line in template literal javascript 
Javascript :: js remove entry 
Javascript :: module export javascript 
Javascript :: how to make a quiz in javascript 
Javascript :: binding style vuejs 
Javascript :: regex validate email 
Javascript :: vue create component 
Javascript :: javascript debugging 
Javascript :: random string javascript 
Javascript :: react hook from 
Javascript :: array.from 
Javascript :: add property with value in js 
Javascript :: react class names 
Javascript :: open source 
Javascript :: jquery dynamic row number not working properly 
Javascript :: formatt json to create node and child node react 
Javascript :: react native tdd emzyme 
Javascript :: capacitorjs get zip code example 
Javascript :: js palindrome number 
Javascript :: why does it say require is not defines 
Javascript :: how to push into an array javascript 
Javascript :: why my expo token change each time 
Javascript :: sequelize special methods 
Javascript :: quokka create-react-app sample 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =