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 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 :: reactnaviataion change title 
Javascript :: geolocation 
Javascript :: obtain only integer not decimal js 
Javascript :: JavaScript - Closures 
Javascript :: mongoose create populate response 
Javascript :: Get async: false 
Javascript :: js how to sort array by object value 
Javascript :: remove all chars from string and leave only numbers javascript and leav space betwin numbers 
Javascript :: numbers split 2 
Javascript :: json schema beispiel 
Javascript :: reactjs import electron 
Javascript :: destructuring object 
Javascript :: react native updating options with setoptions 
Javascript :: loop through elements by name js 
Javascript :: convert days to weeks and days javascript typescript 
Javascript :: accept json data in express 
Javascript :: how to change currency in react-paypal-button-v2 
Javascript :: get buildspec.yml file for react app 
Javascript :: appregistry react native 
Javascript :: spring boot map json to object in controller 
Javascript :: moment get difference between business dates 
Javascript :: how to copy all elements in an array except for the first one in javascript 
Javascript :: push notification react native 
Javascript :: pass object in asyncstorage in react native 
Javascript :: javascript online compiler 
Javascript :: prototype in javascript class 
Javascript :: how to use crypto module in nodejs 
Javascript :: quitar checked jquery 
Javascript :: if javascript 
Javascript :: hook use effect with hooks 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =