Notes for CodeSchool's Javascript Roadtrip 2


1 LOOPS

while loop
runs code as long as boolean is true
while (expression is true) { do this code }

for loop
provides same looping functionality as while
for (initialize var; loop expression; increment var) { do this code }

2 CONDIIONALS

if and else statements
execute code based on conditions
if (condition) {
code
} else {
other code
}

else-if syntax
allows for checking more than one condition
final else is only used if other conditions not met
if (condition) {
code
} else if (condition2) {
code2
} else {
code3
}

nesting conditionals
allows for splitting single conditions
if (condition) {
if (condition2) {
code1
} else {
code2
}
} else {
code 3
}

complex conditionals
&& binary And = true if both conditions are true
|| binary Or = true if either conditions are true

3 BUILT-INS

alert()
send a message to your user

confirm()
ask the user for confirmation
returns a boolean value

prompt()
send a message and retrieve info
returns user entered info

typeof operator
returns type of a variable
typeof 'tim' => string

4 FUNCTIONS

functions take input and give out output
functions are used to repeat step by step something we do repeatedly

syntax
function functionName(parameterOne, parameterTwo) {
code;
return *something or nothing*
}

return keyword instantly exits function

parameters can be expressions and variables

5 ARRAYS

array
data structure that stores data in indexed positions
indices are 0 based

var names = ["tim", "tom"]
names[1] "tom"

length property works on arrays

methods
pop() deletes last value from array and returns its value
push() add a vlue and cell to the end of an array

data can be string, number, variable, arrays, or combination

multilevel arrays can be access bracket notation
names[1][3]

loops with arrays
var names = ["tim", "tom"]
for (i=0; i

Comments

Post new comment

  • Allowed HTML tags: <em> <strong>
  • Lines and paragraphs break automatically.

More information about formatting options

Image CAPTCHA
Enter the characters shown in the image.