JavaScript Functions Flashcards
1
Q
What is the purpose of a function?
(Define)
A
A set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.
2
Q
A function definition (also called a function declaration, or function statement) consists of the function keyword, followed by:
A
- The name of the function.
- A list of parameters to the function, enclosed in parentheses and separated by commas.
- The JavaScript statements that define the function, enclosed in curly brackets, { }.
3
Q
Give example of function syntax.
A
For example, the following code defines a simple function named square:
function square(number) { return number * number; }
4
Q
What is a return keyword do?
A
- It captures the value and returns it.
- It also ends the function.
5
Q
Declaration vs Expression
A
- Declariation
- Normal Syntax
- Expression
- Becomes a function from result of expression (blahblah var = function ()
6
Q
When functions run… what do they return?
A
Whatever is defined in return
If no return keyword is present it is undefined
7
Q
Names of:
- ” “
- ( )
- { }
- []
- | |
- //
- \
A
- Quotes
- Parenthesis
- Braces
- Brackets
- Vertical Bar
- Forward Slashes (Comment - JS)
- Back slash - Show following charachter
8
Q
A