Level 32 Level 34
Level 33

[Quiz] Functions II

101 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

Why do you have to put parenthesis around IIFE?
The most widely accepted way to tell the parser to expect a function expression is just to wrap it in parens, because in JavaScript, parens can't contain statements. At this point, when the parser encoun…
What does the this keyword correspond to?
avaScript uses the this keyword to get a reference to the current execution context
What are functions for?
we separate different parts of the code with them.
to make the code easy to read.
Why do we need to separate different parts of the code?
What are the differences between functions and variables?
functions are variables which contains actions instead of containing pure data as variables do.
What are the three ways of creating a variable with a function?
what is the difference a use-defined function and a built-in function?
user-defined is created by the user of the program language. built-in is created by the creator of the program language
A method is the function of an object.
What is the difference between a method and a function?
we treat them and use them the same way but there are small differences.
is there a difference between how you treat a method and how you treat a function.
Mihez hasonlóan használhatjuk a fu¨ggve´nyeket (function) leginka´bb?
Mappa rendszerhez hasonlóan. a függvények egymásba fészkelhetoek akárhány szinten mint a mappák.
modules or subroutines
What is the name of a function in other languages?
Do anonymous methods exist?
anonymous methods do not exist because a method without a name can not be the function of an object. egy function addig anonymous ameddig el nem mentjük egy változóba.
function name(arguments) { code block }
How do we create (define) a function?
Why do we need to name our functions while we do not give a name to an if statement?
with functions we divide our code into many parts and we need to put a label on each part so that we can identify each part easily.
store blocks of code that you can later call at any time to avoid repetition in your program
function myName () {
What is the syntax of a function?
has to be one word.
What are the rules of how to create the name of a function?
What name should we choose for our function?
the function name should simply be descriptive of what it does.
yes they are.
Are the rules the same for creating names of functions and names of variables?
because functions and variables are the same. the only difference between them is that functions are variables into which action is saved while in variables pure data is saved.
to pass data into a function,
what are the parentheses ( ) for in a function?
What does empty parentheses mean?
no arguments passed into a function
it is creating a function.
What does declaring a function mean?
we call it.
What do we do with a function after it has been declared?
How do we call a function?
What does calling a function mean?
it means that we access the contents of the function and use it.
Yes it is.
Is it a statement when we call a function?
What are statements?
instructions what we want something to happen.
What do we have to put after every statement?
we have to put a semicolon after every statement.
it does not involve any operation with that so it does not make to use variable without any operation.
nothing. it won't be run at all unless you call it.
What happens to the content of the function if the function is only declared but is never called?
no but it is good practice to do so
Do we have to put the declaration first and then the calling of the function?
What is the advantage of doing so?
you get a more organized code a more readable code.
Where should we declare our functions in our files?
it doesn't matter where you put them in your file.
Why does it not matter where we declare our functions in our code?
the JavaScript engine will first do a quick scan of your code and figure out what functions exist before it tries to run anything.
define your functions before you call them.
What is the best practice about using functions?
arguments (php) or parameters (javascript)
What do we call that we pass into the function?
yes. we can.
Can we pass parameters into a function?
inside the parentheses.
Where do we put our parameters in a function?
What parameters do we define inside the parentheses?
how many pieces of information are going to be passed and what do I want to call them.
Will the script still execute with a strict mode error?
Why do we pass data into our functions?
we want to use them inside our function.
with commas.
How do we separate more than one parameters inside the parentheses?
What name can we use for parameters?
You call them whatever you want. It's the same rules as variable naming.
they have a local scope. they are not available outside the function?
What is the scope of the variables which has been used only in the function?
they have to be defined outside the function like this
how can variables be available outside the function, which are used inside the function?
how can you use a variable inside and outside a function at the same time?
you can create a variable with no value (undefined variable) outside the function and you can give it a value inside the function.
it is a built-in function.
is alert() or console.log() a built in or a used-defined function?
What is a built-in function?
it is function created by the creator of JS.
Any data type
The function number() can be used on what types of values?
they can return values.
What can a function do besides the fact that they compute something?
Do we get an error message if we use assignment instead of equality?
What are the curly braces {} for in a function.
we enclose code with them. we enclose an area with them.
What are the parentheses for
that is the window through which you can send stuff inside the braces.
How do we return data from the function?
We use function key (return) word as statement plus the data we want to return.
What is a string literal?
sg that the interpreter does not understand and therefore takes it literally.
does the function have to be defined differently if we return a value?
no it doesn't. This is all we do. however in other programming languages it has to be defined in a different way
Do we have to return sg from our function?
no. You don't have to return anything from a function. It's up to you
what can i do with the data that i return from the function.
I can save it into a variable or i can echo it back.
yes it can. 2 ways.
Can a function be a value for a variable?
3 ways
how to save a function into a variable?
What happens if you call a function but does not return anything.
it will be ignored by the interpreter and nothing will happen unless inside the function we echoed sg. which will be echoed as a result of the fact that the function had been called.
We can effectively just run the function just fine
Will the function run if there are extra data when we call the function?
it might work or it might not.
What happens if i pass too few parameters?
What is a variable scope?
scope of a variable simply means where is this variable visible? What part of your code can see it, what part of your code can use it?
Can we use a variable outside a function which was defined inside a function?
no we can not. because outside the function, as far asJavaScript is concerned, foo doesn't exist.
What is a local variable?
A variable that has been defined within a function and is only valid within that local scope.
How can i make a variable available outside and inside the function at the same time?
we can declare a variable outside the function as well. This now becomes what's called a global variable if it's declared at the absolute top level and outside any function that you have.
inside and outside the function
Where is a global variable available
only inside a function
Where is a local variable available
How can we make a variable global?
outside a function when we create a variable it becomes global.
no we do not need to define it in java script but in php you have to.
if you define a variable outside a function do we need to define it inside the function as well?
How can i make a variable available outside the function in php from inside the function?
in php we can make a global variable from a local variable inside a function by using the global key word statement.
What is global variable?
a global variable is available throughout the page including inside the functions as well.
are global variables available inside the functions?
in php inside the functions they are not available.
Global variable
variable value is available for use anywhere inside the HTML file
does variable scope apply to other code blocks like if statement and loops?
This doesn't apply to other code blocks like loops and if statements and so on.
How does variable scope in javascript and in php differ?
in javascript if you create a variable with var inside the function, it only exits inside the function; otherwise, it's available everywhere.
A statement is an action.
rules of user defined functions
What is a user-defined object?
object created by the user
What is a built-in object?
object created by the developer of the programming language.
is there a built-in variable?
no there is not. variables are only created by users.
are there user-defined properties of a variable?
no there are not. all of the properties are built-in.
Returns the Document object for the window (See Document object)
nothing. such a property does not exist.
What can we assign into a the user-defined property of a variable?
since a user-defined variable does not have user-defined properties it is only possible
When can we assign an anonymous function, a named function and a user defined variable into a the user-defined property of a user-defined variable?
Can we create properties for user-defined variables?
briefly we can only create properties for user-defined objects but we can not for variables. (eze´rt mondhatta a tana´r bogy a variable az object de me´g sem teljesen. )
What becomes of a user defined variable if we save a function into it?
if we save an function into a variable that variable will become a function. if we save a variable into a variable that variable will stay a variable.
How do we treat functions that write out simething or do some actions?
If functions or methods write out something or do some action they should be treated as actions (as statements) (they do not have to be saved into a variable or user-defined property )
How do we treat functions that only return a value?
if they only return a value they should be treated as values. (they should be saved / assigned into a variable or user-defined property.
When can we not save a function into a variable?
so it does not matter if a function does some actions or returns a value it can always be saved into a variable or user- defined property.
Alma = getelementbyid();
itt az erdmeny mentjuk el a valtozoba
Alma = function (){};
itt functiont mentjuk el a valtozoba
Alma = getelementbyid; (this is a named function)
itt a named function-t mentjük el a változóba.
it will run as soon as the interpreter reads it.
When does the anonymous function run if we do not save it to a variable? just write it down in our code?
Alma = getelementbyid;
Ha hasznalom egy named function eseteben a ()jeleket akkor a returned value (a function a´ltal visszaku¨ldo¨tt e´rte´k ) lesz elmentve ha nem hasznalom a () jeleket egy function uta´n akkor pedig a function maga lesz elmentve
What are we supposed to do with a function that returns a value?
we can always call a function without assigning it to a variable but if the function returns a value and does no other actions besides that then the only reasonable thing is to assig…
What can we do with the returned value?
we can save it to a variable or echo it back to the browser.
myVariable = myFunction();
how to save a value from a function into a variable?
very important.
What will the property or variable become if a function is saved into it?