Function expressions Flashcards

1
Q

Omitting a name is allowed for Function Expressions or declarations?

A

Function Expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

function sayHi() {
alert( “Hello” );
}

alert( sayHi ); // returns?

A

function code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In JavaScript, a function is a _______

A

value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

function sayHi() {
return console.log(‘Hello’);
};

let func = sayHi();

func; // returns?

A

Hello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

why do Function Expressions have a semicolon ; at the end, but Function Declarations do not

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

function sayHi() { // (1) create
alert( “Hello” );
}
let func = sayHi; // (2) copy

sayHi as not () because?

A

func = sayHi() would write the result of the call sayHi() into func, not the function sayHi itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

function sum(a, b) {
return a + b;
}

Declaration or expression?

A

Declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

let sum = function(a, b) {
return a + b;
};

Declaration or expression?

A

expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A Function _______ is created when the execution reaches it and is usable only from that moment.

A

Expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A Function _________ can be called earlier than it is defined.

A

Declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

function myFirst() {
return myDisplayer(“Hello”);
}

function mySecond() {
return myDisplayer(“Goodbye”);
}

myFirst();
mySecond();

// what is returned and why?

A

Goodbye

JavaScript functions are executed in the sequence they are called. Not in the sequence they are defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

For example, a global Function __________ is visible in the whole script, no matter where it is.

A

Declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

sayHi(“John”);

function sayHi(name) {
alert( Hello, ${name} );
}

The above returns and why?

A

Hello, John

And after all Function Declarations are processed, the code is executed. So it has access to these functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

sayHi(“John”); /

let sayHi = function(name) {
alert( Hello, ${name} );
};

The above returns and why?

A

error!

Function Expressions are created when the execution reaches them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In ______ when a Function Declaration is within a code block, it’s visible everywhere inside that block. But not outside of it.

A

strict mode,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A Function _______ is only visible inside the code block in which it resides.

A

Declaration

17
Q

Function _______ are processed before the code block is executed. They are visible everywhere in the block.

A

Declaration