Lesson 3: Introduction to Functions Flashcards
1
Q
Some Function Concepts:
A
- Functions are reusable.
- Functions make code easier to debug and maintain.
- Functions need to be called to run its statements.
2
Q
Show how a function can be used to handle events:
A
onclick=”sayHello();”
3
Q
What is a Method?
A
Functions that “belong” to a specific object.
4
Q
Write a Return Value:
A
function hello () { return 'hello world!'; } const message = hello();
5
Q
What are Parameters and arguments?
A
Terms used to represent data provided for the functions as inputs.
6
Q
When a function is invoked, what are the inputs provided called?
A
Arguments.
7
Q
When are Parameters set?
A
When the function is defined.
8
Q
Show a function call being used for another function call:
A
let wall = getArea(3, 5); alert(wall);
9
Q
What is an Anonymous Function?
A
A function that doesn’t have a name.
10
Q
Show an example of an Anonymous Function:
A
const goodbye = function() { console.log('goodbye world'); };
11
Q
General Functions Syntax:
A
function sayHello() { alert("Hello"); }
12
Q
Show a function that calculates the cube of a number and displays the result”
A
function cube (x) { alert(x * x * x); }