Function expressions Flashcards
Omitting a name is allowed for Function Expressions or declarations?
Function Expressions
function sayHi() {
alert( “Hello” );
}
alert( sayHi ); // returns?
function code
In JavaScript, a function is a _______
value
function sayHi() {
return console.log(‘Hello’);
};
let func = sayHi();
func; // returns?
Hello
why do Function Expressions have a semicolon ; at the end, but Function Declarations do not
a Function Expression is created here as function(…) {…} inside the assignment statement: let sayHi = …;. The semicolon ; is recommended at the end of the statement, it’s not a part of the function syntax.
function sayHi() { // (1) create
alert( “Hello” );
}
let func = sayHi; // (2) copy
sayHi as not () because?
func = sayHi() would write the result of the call sayHi() into func, not the function sayHi itself.
function sum(a, b) {
return a + b;
}
Declaration or expression?
Declaration
let sum = function(a, b) {
return a + b;
};
Declaration or expression?
expression
A Function _______ is created when the execution reaches it and is usable only from that moment.
Expression
A Function _________ can be called earlier than it is defined.
Declaration
function myFirst() {
return myDisplayer(“Hello”);
}
function mySecond() {
return myDisplayer(“Goodbye”);
}
myFirst();
mySecond();
// what is returned and why?
Goodbye
JavaScript functions are executed in the sequence they are called. Not in the sequence they are defined.
For example, a global Function __________ is visible in the whole script, no matter where it is.
Declaration
sayHi(“John”);
function sayHi(name) {
alert( Hello, ${name}
);
}
The above returns and why?
Hello, John
And after all Function Declarations are processed, the code is executed. So it has access to these functions.
sayHi(“John”); /
let sayHi = function(name) {
alert( Hello, ${name}
);
};
The above returns and why?
error!
Function Expressions are created when the execution reaches them.
In ______ when a Function Declaration is within a code block, it’s visible everywhere inside that block. But not outside of it.
strict mode,