Basic Flashcards
push()
Adds item to the end of an array.
i.e. arr.push(“name”);
pop()
Removes item from the end of an array.
i.e. arr.pop();
item can also be assigned to a variable.
i.e. myVar = arr.pop();
shift()
Adds item to the front of an array.
i.e. arr.shift(“name”);
unshift()
Removes item from the front of an array.
i.e. arr.unshift();
item can also be assigned to a variable.
i.e. myVar = arr.unshift();
length
Can be used for the length of a string or an array.
i.e. myString.length
===
Strict Equality tests both data and type. It will not convert a string to a number like == will.
!==
Strict Inequality tests both data and type. It will not convert a string to a number like != will.
How are case statements evaluated?
With strict equality, ===
What are the two ways to access the properties of an object?
Dot Notation: myObj.property; or Bracket Notation: myObj["property"]; Bracket notation can also be used with a variable. myProp="property"; myObj[myProp];
How do you delete a property from an object?
delete myObj.property;
How to you add a property to an object?
myObj.myProp = “property”;
How do you check if a property exists on an object?
myObj.hasOwnProperty(“property”);
returns true if property exists.
How do you generate a random number?
Math.random();
Returns a whole number between 0 and almost 1, but it doesn’t actually get to 1.
How do you round down to the next whole number?
Math.floor();
How do you generate a whole number between 0 and 9?
Math.floor(Math.random() * 10);