Modular, loops, strings. Flashcards
difference between parameter and argument.
- argument is more specific than the parameter
- parameters can have multiple arguments
function addTwoNumbers(a, b) {
var result = a + b; alert(result); }
addTwoNumbers(5, 10);
*what is the parameter?
the inputs of a, b
function addTwoNumbers(a, b) {
var result = a + b; alert(result); }
addTwoNumbers(5, 10);
*what is the argument?
the inputs of 5, 10
variable scope
- variables created within a function
- these variables are limited to the function
Suppose you create a function:
function myFunction() { var x = 500
}
Now, if you simply wrote code to alert (x), nothing will happen because X was created within the function and limited to the function.
global variable
- variable created outside of a function.
- can be used anywhere in your code
scripts tag
- used to link other javascript pages together
- think external stylesheet for javascript
javascript script tag
what does it look like?
iteration
the process of looping code
sometimes iteration IS called loop or looping
to use the javascript looping or iteration ability, we replace…
if with while
example:
var a = 1;
while (a >10) {
alert (a)
}
infinite loop
- the result of not incrementing or modifying an index
steps to creating a loop using WHILE
1) set up the index
2) check the condition
3) increment the index
for loop
simplifies the while loop
use the for loop:
var i = 1 while (i
for (var i=1; i
do while loop
executes the loop before checking the condition
change to do while loop
var i = 1 while (i
var i = 1;
do {i++
} while ( i