simple javascript function
function idk() {
alert('This is an alert!')
}
//call the function to make the function run by saying "Name of function + ()"
idk()
simple javascript function
function idk() {
alert('This is an alert!')
}
//call the function to make the function run by saying "Name of function + ()"
idk()
function javascript
var x = myFunction(4, 3); // 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
}
js function
function name(parameter1, parameter2, parameter3) {
// what the function does
}
js function
function myfunction() {
console.log("function");
};
myfunction() //Should say "function" in the console.
function calculate(x, y, op) {
var answer;
if ( op = "add" ) {
answer = x + y;
};
else if ( op = "sub" ) {
answer = x - y;
};
else if ( op = "multi" ) {
answer = x * y;
};
else if ( op = "divide" ) {
answer = x / y;
};
else {
answer = "Error";
};
return answer;
};
console.log(calculate(15, 3, "divide")); //Should say 5 in console.
//I hope I helped!
js function
var x = 10;
function créerFonction1() {
var x = 20;
return new Function("return x;"); // ici |x| fait référence au |x| global
}
function créerFonction2() {
var x = 20;
function f() {
return x; // ici |x| fait référence au |x| local juste avant
}
return f;
}
var f1 = créerFonction1();
console.log(f1()); // 10
var f2 = créerFonction2();
console.log(f2()); // 20
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us