mode 4 JS II Flashcards
What is an array?
- a group of data entries
- Each data entry has an index associated with it. indeces begin with (0) to (arraySize -1)
how do we declare an array?
how do you see all the contents of an array?
how do you obtain the length of the array (the # of elements)?
how do you access elements in an array?
how do we declare an array? var arrayOne= ['Billy', 'Katherine']; // remember, JS is loosely typed var arrayTwo= ['Billy', 'Katherine', 77, false]; // 0 1 2 3
// how do you see all the contents of an array? console.log(arrayTwo);
// how do you obtain the length of the array (the # of elements)? //console.log(arrayTwo.length); // prints "4"
// how do you access elements in an array? //console.log(arrayTwo[0]); // prints "Billy"
what if you attempt to access an element that doesn’t exist?
what if you attempt to update an element that doesn’t exist?
how do I dynamically remove elements from an array?
//what if you attempt to access an element that doesn't exist? var arrayOne= ['Billy', 'Katherine']; // remember, JS is loosely typed var arrayTwo= ['Billy', 'Katherine', 77, false]; // 0 1 2 3
console.log(arrayTwo[50]); //prints “undefined”
//what if you attempt to update an element that doesn't exist? arrayTwo[6]="does this work?"; // console.log(arrayTwo); // console.log(arrayTwo[5]); //prints "undefined" // console.log(arrayTwo[6]); //prints "does this work?"
//how do I dynamically remove elements from an array? var arrayDelete = [6, 8, 10, 12]; delete arrayDelete[1]; console.log(arrayDelete); console.log(arrayDelete[1]); //prints "undefined"
What is an object?
- a model of a real world physical object
- it has state and behavior
- in JS, objects are key-value pairs
how do I create an object?
var objectOne = { // to declare a member of an object, you use key-value pairs // attribute: value
name: "Danny Boy", 'ability': 'electromagnetism', 'official bounty': 250000,
// this is how you'd add a method doCrimeMethod: function(){ // method logic console.log("inside doCrimeMethod()") } }
What is a function?
- a reusable block of code
- it performs some service for the rest of the application
What is the different between an argument and a parameter?
- parameters are used to declare WHICH variables a function/method will use.
- arguments are the actual values passed into a function/method as it is invoked
how do I declare a function?
function myFunction(){}
//I can also give a function parameters
var myFunctionTwo = function (lePokemans, leMoveSet){
console.log(“The objective best pokemon is: “+lePokemans);
console.log(leMoveSet);
What is control flow?
- control flow are a series of functionalities that allow the developers to alter the logical flow of the application
- normally in an application lines of logic are read top to bottom. Using control flow we can alter the way the lines of logic are ready. We can make lines of code repeat or even be skipped
Keywords associated with control flow?
- if, else if, else
- while, for, do-while, foreach
- switch
- break, continue
- ”?” and the ternary operator
What are the TRUTHY values in JS?
Anything that isn’t a FALSEY value
What are the FALSEY values in JS?
false, 0, “”, null, NaN, undefined
Short-circuiting
Short circuiting
T and T = T T and F = F F and T = F F and F = F T or T = T T or F = T F or T = T F or F = F shortcircuiting operators: && , || bitwise operators: & , |, ^, etc
What is a string?
a primitive datatype in JS
it represents a series of characters
how do I create a string?
var name= ‘Billy “The Warden”’;