const add = function(x,y){
return x+y;
?
The difference is the first one gets hoisted.
not much, really
can u explain hoisted?
should we define like const or without const?
https://lmgtfy.app/?q=difference+between+function+declaration+and+function+expression
I read that the difference is that one is function declaration (without const) and the other one is a function expression (with const). "Function declarations load before any code is executed while Function expressions load only when the interpreter reaches that line of code."
Hoisting means that function declarations (without const) get moved to the top of the code. This way you can call a function anywhere within your code: console.log(myFn()); //works fine! //Even when we write the function later 👇🏽 function myFn(){ return "hello"; }
It get moved to the top of the block it's in, which means one level up in the nesting chain, not necessarily to the top of the code. ✌️
It gets moved to one of the blocks higher up, which means some levels up in the nesting chain, not necessarily to the top of the code. ✌️
if you say we can't change the const variables and any const! but why here we changed the const arrays? without no error const colors_1 = ["red", "blue", "green"]; const colors_2 = ["black", "white", "teal"]; const colors_3 = colors_1.concat(colors_2); console.log(colors_3);
you didn't change any constant here. just an expression that gets evaluated & stored in the colors_3 variable.
Обсуждают сегодня