IES: JS-deck 12 Flashcards
1
Q
JS Asterisk
A
- the arithmetical multiplication operator in JavaScript
2
Q
JS Function Block
A
- can include a Return statement
- Common for statements in a function block to include calls to functions outside that function block
3
Q
JS Return Statement
A
- Can be included in / omitted from a JS function block
- without a value specified, function will return “undefined”
- Causes script flow to continue at caller
- No further function statements get executed
- Typical to pass manipulated argument values result to caller
Ex.
function function-name ( parameter, parameter ) {
// Statements to be executed go here.
return result
}
4
Q
JS Invoke
A
- definition: called to execute their statements whenever required
- A usefulness of JS “functions”
- Entering different arguments, a caller can effect different results
5
Q
JS Parentheses
A
- JS operator
- Component of the call statement
- What actually calls the function
- A statement can assign a function to a variable by specifying just the function name (i.e. without the ( ) operator).
- A function name followed by ( ) will invoke the function and will return the assigned function value
6
Q
JS Interpreter
A
- reads scripts in top-to-bottom order
- Makes two sweeps
1. First Sweep: - Looks for function declarations
- remembers any found in a process known as “hoisting”
2. Second sweep: - the script is executed
7
Q
JS Hoisting
A
- the process whereby the interpreter appears to move the declaration of functions, variables, classes, or imports to the top of their scope, prior to execution of the code
- Occurs in the first sweep of the JS interpreter
- The JS interpreter looks for and remembers function declarations
- Allows function calls to appear in the script before the function declaration
- (the first sweep does not recognize functions using “let” or “const” keywords to assign variables)
8
Q
JS self-invoking function expressions
A
- a.k.a. IFFE (often pronounced- “iffy”)
- IFFE: Immediately Invoked Function Expressions
- Anonymous function expressions can be made “self-invoking” by enclosing entire function in ( ) and adding the ( ) operator at the end of the expression
syntax:
(function ( ) {statements; return value}) ( ) - This means that their statements are automatically executed one time when the script is first loaded by the browser
9
Q
JS anonymous functions
A
- a function name can be omitted when assigning a function to a variable
- This omission is possible because the function can be called in a statement specifying the variable name and the ( ) operator
- When assigning a named function to a variable, only specify the function name in the statement
syntax:
let variable = function (parameters) {statements; return value} - Can be made “self-invoking” by enclosing entire function in ( ) and adding the ( ) operator at the end of the expression
syntax:
(function ( ) {statements; return value} ) ( )
10
Q
JS “lexical scope”
A
- the environment in which the variable was created
- Can be either “Global” or “local”
- Determines the extent to which variables are accessible in their scripts
11
Q
JS “global scope”
A
- A lexical scope
- refers to variables created outside function blocks
- Accessible globally during entire script (exists continuously and is available to functions within same script environment)
- can cause conflicts: can allow for variables of the same name but with different values to exist in the same environment
- Conflict potential is best avoided by never creating global variables which store primitive values
12
Q
JS “primitive values”
A
- all data types except “object” and “function”
13
Q
JS “local scope”
A
- a lexical scope
- variables created inside function blocks (Good practice: declare variables at the very beginning of a function block)
- Accessible locally throughout the function life (exists until function ends or until it returns)
- Recommended: try to create only local variables to store values within your scripts (avoids conflicts: like-named variables can exist within separate, included functions in the same script)
14
Q
JS store-value keywords
A
- “var”: allows like-named conflicting variables to overwrite their assigned values without warning
1. And older keyword - “let” and “const”:
1. More recent keywords
2. Prohibit overwriting their assigned values without warning
3. recognize like-named conflicting variables as an “Uncaught SyntaxError” - Recommended: create variables declared using the “let” or “const” keywords to store values within your scripts
15
Q
A