Level 31 Level 33
Level 32

[Quiz] Functions


97 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

Ignore?
Javascript Function
a series of statements together, a block of code, to perform a specific task.
Calling
The function asking to perform its task.
Parameters
Pieces of information passed to a function.
Return Value
The response of a function providing you an answer.
Function
store blocks of code that you can later call at any time to avoid repetition in your program
sayHello()
Function Name
Function Declaration
Creates a function that you can call later in your code.
Named Function
A function with a name
Function Expression
A misplaced function where you would normally expect to see an expression. Ex. var area = function(width, height) {
Anonymous function
A function with no name.
Immediately Invoked Function Expressions
Functions not given a name. They are executed once the interpreter comes across them.
Grouping Operators
Parentheses to ensure the interpreter treats this as an expression.
Function Example
function sayHello () {
Functions with information example
function getArea(width, height) {
function getArea(width, height) {
Calling functions that need information example
functions
JavaScript treats _______ as first-class objects.
Calls
When something invokes and executes a function.
lowerCamelCase
each word (except the first) begins with a capital letter
function keyword
Tells the computer that you are making a function
Parameter
Variable passed on. Values function will compute on
Between { }
Where you write your block of reusable code.
;
Ends every line of code in a block of code.
+
Adds two values together or concatenates two strings into a single string.
var keyword
Declares a variable.
Parentheses ( )
Parameter is in
code block
the reusable code that is between the curly brackets {}
Call the function
To use the function, we _______ by just typing the function's name, and putting a parameter value inside parentheses after it. The computer will run the reusable code with the specific parameter value substituted into the code.
Why functions are useful
You want to use your code over and over again but you want to use that code with different inputs.
Why do you add white space
The computer can understand the code without spacing but it makes editing a lot easier and is best practice.
Semi-colon
Put a _______at the end of each line of code in the reusable block and at the end of the entire function.
Period
The semi-colon acts like a _______ in a sentence. It helps the computer know where there are stopping points in the code.
debugging
figuring out what went wrong with your code
Important in programming. No repeating!
Don't Repeat Yourself (D.R.Y) - The D.R.Y. principle
Reusable block - the code inside {}
The part that you keep repeating will be this.
return a value
Gives the programmer back the value that comes out of the function.
return
keyword that gives the programmer back the value that comes out of the function
Enter a value for each parameter in the parentheses
To call a function with more than one parameter.
Outside
Variables defined _______ a function are accessible anywhere once they have been declared.
Global
Variables defined outside a function are _______ variables and their scope is _______.
Local
who has more priority for the same name – glob vars or local vars?
local variables
defined inside a function; they cannot be accessed outside of that function
Current
The var keyword creates a new variable in the _______ scope. That means if var is used outside a function, that variable has a global scope. If var is used inside a function, that variable has a local scope.
in 4 different ways.
How many ways can js functions be evoked?
How do they differ from each other?
Each method differs in how this is initialized.
What is "this" keyword for?
In JavaScript, the thing called this, is the object that "owns" the current code.
it is the object that "owns" the function.
What is the value of "this" when used in a function?
is "this" a variable? can its value be changed?
Note that this is not a variable. It is a keyword. You cannot change the value of this.
Is the code in a function executed when the function is defined?
The code in a function is not executed when the function is defined. It is executed when the function is invoked.
What is the other word for envoking a function?
Some people use the term "call a function" instead of "invoke a function".It is also quite common to say "call upon a function", "start a function", or "execute a function".
Why do we use envoke a function instead of calling a function?
In this tutorial, we will use invoke, because a JavaScript function can be invoked without being called.
when
with function expessions
Invoking a Function as a Function
Invoking a declared Function as a Function
Does a declared function like the previous one belong to any object?
The previous function does not belong to any object. But in JavaScript there is always a default global object.
What is the defult global object in HTML?
In HTML the default global object is the HTML page itself, so the function above "belongs" to the HTML page.
What is the page object in a browser?
In a browser the page object is the browser window. The function above automatically becomes a window function.
is myFunction() and window.myFunction() different?
myFunction() and window.myFunction() is the same function:
window.myFunction(10, 2);
This is a common way to invoke a JavaScript function, but not a good practice in computer programming.
What does this refer to if a function is called without an owner object?
When a function is called without an owner object, the value of this becomes the global object.
What is the gobal object in a webrowser?
In a web browser the global object is the browser window.
myFunction();
Call the function
What if we invoke a function as a global function?
Invoking a function as a global function, causes the value of this to be the global object.
What might happen if we use the window object as a variable?
Using the window object as a variable can easily crash your program.
What is the fullName?
The fullName method is a function.
Where does fullName function belong to?
The function belongs to the object.
myObject is the owner of the function.
What is the owner of the fullName function?
What is "this" this time?
The thing called this, is the object that "owns" the JavaScript code. In this case the value of this is myObject.
...
What is the difference between a user-defined object or a object constructor
Invoking a function as an object method, causes the value of this to be the object itself.
What will be the value of "this" inside the code block of the function if we Invoke the function as the method of an object?
when can we say that the function is invoked with a constructor?
If a function invocation is preceded with the new keyword, it is a constructor invocation.
they look the same.
what is the difference between the function constructor and the object constructor?
What do we create with a constructor invocation? step 2
A constructor invocation creates a new object. The new object inherits the properties and methods from its constructor.
What is the function construction like?
it is like a class in php
What is the value of "this" in a function constructor?
The this keyword in the constructor does not have a value.
What are functions in js?
In JavaScript, functions are objects.
What do objects have in js?
JavaScript functions have properties and methods.
call() and apply() are predefined JavaScript function methods.
What are the 2 predefined function methods by which we can invoke a function?
What do both of the methods have to have?
both methods must have the owner object as first parameter.
an example of apply()
function myFunction(a, b) {
Both methods takes an owner object as the first argument.
Where do we put the object when using apply() or call() methods?
What is the only difference between apply() and call() methods?
The only difference is that call() takes the function arguments separately, and apply() takes the function arguments in an array.
in strict javascript mode which argument becomes the value of this?
In JavaScript strict mode, the first argument becomes the value of this in the invoked function, even if the argument is not an object. "so it creates an object from anying. "
What is the advantage of using call and apply methods?
With call() or apply() you can set the value of this inside the function and invoke the function as a new method of an existing object.
we make a method for an existing object.
What do we make from a function with call and apply?
Does js function perform any checking on parameter values?
A JavaScript function does not perform any checking on parameter values (arguments).
What are function parameters?
Function parameters are the names listed in the function definition.
What are function arguments?
Function arguments are the real values passed to (and received by) the function.
What if we call a function with less arguments than it was declared with?
If a function is called with missing arguments (less than declared), the missing values are set to: undefined
it is better to assign a default value to the parameter:
What is best solution when we call a function with less arguments
function myFunction(x, y) {
How to assign a default value to a parameter?
they test
What does logical expressions do?
y || 0;
If y is defined, y || returns y, because y is true, otherwise it returns 0, because undefined is false.
if (y) + code block
if the variable is set or not.
What if a function is called with too many arguments?
If a function is called with too many arguments (more than declared), these arguments cannot be referred, because they don't have a name. They can only be reached in the arguments object.
What is argument object?
JavaScript functions have a built-in object called the arguments object.
When do we use the argument array object?
The argument array object contains an array of the arguments used in the function that was called (invoked).
What is getElementById("alma") equal to?
it is equal to the alma element that it returns. its value is the alma element. the handler of the alma element.
x.onclick.....
nothing. x = getElementById("alma")