0
How does the function run even though i have not called it
function sayHello(name) { var text = 'Hello ' + name; var say = function() { console.log(text); } say(); } var x = sayHello('Joe');
11 ответов
+ 1
3) when a function is called before declaration of the function
// it uses it as the main function
and vice versa if uses as the secondary /sub function
//if multiple declaration of sayNumber()
then
if there is only one function with saynumber();
then depends on only one function declared
0
when the program gets the first name in anywhere inside after declaration of a function,
the compiler knows program is calling the function
example:- declared anywhere
0
Then how do I assign sayHello('Joe') to X without calling the function
0
use different name , do not use the name of the function
0
Can you give me an example
0
var y= // anything else
0
@Rajeeb
function say667() {
var num = 42;
var say = function() { console.log(num); }
num++;
return say;
}
var sayNumber = say667();
sayNumber();
//Output: 43
function say667() {
var num = 42;
var say = function() { console.log(num); }
num++;
return say;
}
var sayNumber = say667();
//Output: Blank
1. Why does num = 43(and not 42) although ++ operator is after the function say()?
2. Why is there no output when I removed sayNumber();
3. What does sayNumber(); exactly do
4. Why is there a necessity to have return say;
I am a newbie and i have a lot of questions, please bear with me! It will really make my day if you answer these questions for me
0
1) multiple declaration of functions sayNumber()
, where one function will affect the other
the variable num gets affected twice in the code
// num= 43 not 42
0
2) // no output
no call for the function second time
at the end of second function saynumber
0
4) return necessity
to return a value to the function
no necessary unless you provide arguments to the functions
0
Can you elaborate Number 1. Thank You