Scroll to see replies
console.log("I want to eat " + " " + food);
console.log("I want to eat " + " " + food);
var orangeCost = function(cost) {
console.log(cost * 5);
};
orangeCost("5");
var orangeCost = function(cost) {
console.log(cost * 5);
};
orangeCost("5");
To my mind, the last line should be: cost("5"; because I thought I told it that the function 'cost' will change, but that the rest of the code in curly brackets should stay the same.... Instead it looks like I told it that the function 'cost' will change and then went ahead and called the variable in the last line, not the function Spoiler
function orangeCost(arg){
}
orangeCost(5);
var orangeCost = function(cost) {
console.log(cost * 5);
};
orangeCost("5")
http.get("SomeUrl",function() {
//do some stuff on success
},function(){
//do some stuff on failior
}
);
doStuff();
var doStuff = function(){};
doStuff();
function doStuff(){
}
function orangeCost(arg){
}
orangeCost(5);
Is the most common way. That is called a function declaration. You've declared a function named orangeCost and are calling it passing '5' as the parameter.
var orangeCost = function(cost) {
console.log(cost * 5);
};
orangeCost("5"
The way you did it is called a 'function expression' which lets you declare a function as part of an expression - It is often used when you want to pass functions around as arguments.
http.get("SomeUrl",function(){
//do some stuff on success
},function(){
//do some stuff on failior
};
Notice those functions don't have names that is because function expressions can be anonymous!
doStuff();
var doStuff = function(){};
That code is invalid because doStuff() doesnt exist at the point it is called.
doStuff();
function doStuff(){
}
Is valid because 'function' declarations are 'hoisted ' to the top by javascript whilst function expressions are not.Last reply 1 month ago
Free website hosting providers with no strings attached?Posted 3 months ago
iDEA silver citizen badge three. Milkshake shack coding problem.Last reply 4 months ago
How do you practice programming java for beginners?Last reply 8 months ago
hows the employment market for tech work in the UK?Last reply 1 month ago
Free website hosting providers with no strings attached?Posted 3 months ago
iDEA silver citizen badge three. Milkshake shack coding problem.Last reply 4 months ago
How do you practice programming java for beginners?Last reply 8 months ago
hows the employment market for tech work in the UK?