camelCase
no dashes
no periods
can't start with a number
it CAN start with $ or underscore
Back
compound assignment operators
+= -= *= /=
Front
Compound assignment operators that (adds or subtracts or multiples or divides) the right-hand operand by the left and stores the result in the left-hand operand; Ex:
a += b is equivalent to a = a + b.
Back
what is the format for a switch statement that includes 2 cases and one default?
Front
function guessNum(num) {
var answer = " ";
switch(num) {
case 1: //if the answer == 1
answer = "you got it right!";
break; //all cases end with this
case 2:
answer = "just missed it";
break;
default: //like else: statement
answer = "nope";
break;
}
return answer;
}
Back
How do you access 11 and 13 in the following array?
var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
Front
arr[3][0][1]; // 11
arr[3][1]; //13
Back
What is the syntax for an if statement that evaluates whether myNum is true?
Front
function test (myNum) {
if (myNum === 7) {
return "It was true";
}
return "It was false";
} //notice no semiconlon to close
Back
When do you HAVE to use bracket notation to access an object's properties?
Front
When the property has a space in it's name. EX:
myObj["space name"];
Back
multiline comment
Front
/ comment here /
Back
define a variable
Front
Multiple ways:
_______________________
var name;
name = "Molly";
_____________________________
var name = "Molly";
______________________________
var name, age;
name = "Molly";
age = 5;
_______________________
var name = "Molly", quantity = 14;
Back
What does a return do?
Front
It provides a value from a function. Note: nothing that is written after the return statement in the function will execute. Once a you hit the return value, the function is automatically exited
Back
What does the typeof operator do?
Front
determines the type of variable for value. Ex:
typeof 7;
>number
typeof "hello";
>string
Back
Can a function be called before it is declared
Front
Yes. In JavaScript this okay (as long as declared later in script).
Back
How do you set up a for loop?
Front
for (initialization; condition; final expression) {
};
ex:
var ourArray = [ ];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
Back
single line comment
Front
// comment here
Back
Function Expression
Front
var area = function(width, height) {
return width * height;
};
//notice semicolon!
Different from anonymous function. It cannot be called before you define it!
Back
How do you delete a property of an object?
Front
delete hotel.name;
Back
How do add a new item to the FRONT of an array?
Front
array.unshift()
Back
How do you access the 2nd letter of the following variable:
var myStr = "Lindsey";
Front
myStr[1];
*Note bracket notation can just be used here to access character--it CAN'T change the character.
Back
How do you create an array literal?
Front
var colors;
colors = ['white', 'red', 'green'];
*numbering of arrays starts at 0! Here, 0 is the index and white is its value.
Back
How do you find calculate the number of characters in the variable myStr?
Front
var stringLength = myStr.length;
Back
Return value
Front
When you expect function to provide you with a value. Note: nothing that is written after the return statement in the function will execute.
Back
How do you clear the value of an object's property?
Front
hotel.name = ' ';
Back
How do you link JS script to HTML file
Front
<script type="text/javascript" src="script.js"></script> *generally added at end, before </body> tag
Back
what does -- do in JS?
Front
decrement, subtracts one from current number
i--;
Back
How do you call function getArea with the parameters 3 and 5?
Front
getArea(3, 5);
Back
What is the difference between equality operator (==) and strict equality (===) ?
Front
== attempt to convert both values to a common type; === does not
Ex: 3 == '3' //true
3 === '3' //false
Back
How do you create an object with constructor notation?
Front
var hotel = new Object();
hotel.name = 'Quay';
hotel.checkAvailability = function() {
return this.rooms - this.booked;
};
*note name is the key and Quay is the value.
Back
How do you change the third item in the array named colors?
Front
colors[2] = 'beige';
Back
How do you alter the name property of the object dog with both bracket and dot notation?
Front
dog["name"] = "Rudy";
dog.name = "Rudy;
Back
What is an Immediately Invoked Function Expression (IIFE)
Front
Not given a name. They are involved as soon as interpreter reaches them. Ex:
var area = (function() {
var width = 3;
var height = 2;
return width * height;
} () );
*parens near end tell interpreter to run immediately. Any variables in anon. functin won't conflict with variables with same name in script.
Back
What are global variables?
Front
They are created outside a function. They can be used anywhere. (Note* they use more memory and can make scripts slower).
Back
What method do you use to check if an object has a certain property?
Front
.hasOwnProperty(propname);
Ex: dog.hasOwnProperty("name");
//note strings on name--even with dot notation!
Back
How do you push "green" onto the array colors?
Front
colors.push("green"); //adds green to end of array
Back
How do add the property sound to the object dog using both bracket and dot notation?
How do you access the length of the array named colors?
Front
colors.length;
Back
Can a function be called before it is declared
Front
Yes. In JavaScript this okay (as long as variable is declared later in script).
Back
What is the syntax for a multi-dimensional array to hold the names of NBA players separated by team?
Front
var NBAplayers = [["Laker1", "Laker2"], ["Celtic1", "Celtic2"]];
Back
How do you remove the FIRST element from an array?
Front
array.shift();
//takes no argument, just empty parens
Back
How do you find the last index of an array with an unknown amount of items?
Front
myArray.length -1
Back
How do you remove the last element from the following: colors = ["red", "blue", "green"];
Front
colors.pop(); //pop always removes the last element of an array
Back
what does || do?
Front
logical or operator. It returns true if either of the operands are true.
if (num < 5 || num > 10) {
return "Yes":
}
Back
How do you change the third item in the array named colors?
Front
colors[2] = 'beige';
Back
what is the syntax for the object dog with the properties name and legs?
Front
var dog = {
name: "Kaya",
legs: 4
};
NOTE: commas used to separate properties and semicolon used at end of object
Back
How do you access an object (using dot notation)?
Front
var hotelName = hotel.name;
(or you can use square brackets, but NOT to access methods)
var hotelName = hotel['name'];
Back
what does && do?
Front
logical and operator: returns true if and only if the operands to the left and right of operator are true. Ex:
if (num > 5 && num < 10) {
return "Yes":
}
Back
what is the order of if/else if/ and else conditions?
Front
if
else if
else if
else (only final statement)
Back
How do you delete the property sound from the object dog using both dot and bracket notation?
Front
delete dog.sound;
delete dog["sound"];
Back
What is an Immediately Invoked Function Expression (IIFE)
Front
Not given a name. They are involved as soon as interpreter reaches them. Ex:
var area = (function() {
var width = 3;
var height = 2;
return width * height;
} () );
*parens near end tell interpreter to run immediately. Any variables in anon. function won't conflict with variables with same name in script.
Back
--
Front
decrement, subtracts from from current number
i--;
Back
How do you create an array literal?
Front
var colors = ['white', 'red', 'green'];
*numbering of arrays starts at 0! Here, 0 is the index and white is its value.
Back
Section 2
(16 cards)
What does the const keyword do?
Front
It assigns a variable. Use it for values that you don't want to ever change. (name const variables in all caps) const DAYSINWEEK
Back
What does the let keyword do?
Front
Sets a variable--but unlike var it doesn't allow you to overwrite an existing variable that was previously defined by let
Back
What is the format for a conditional operator (Ternary operator)?
Front
condition ? statement-if-true : statement-if-false
return a > b ? "a is greater" : "b is greater";
Back
What does the 2 stand for in parseInt("11", 2)
Front
The 2 fills the radix position, which specifies base. The base here is 2 (binary). If there is no radix specified, the default is base 10.
Back
What does the .reduce() method do?
Front
It applies a function to EACH element in an existing array and reduces the array to a single value, which is assigned to a new array. It does not alter the existing array.
Back
How can I write this shorthand:
const addThis = function(num1, num2) {
return num1 + num2;
}
Front
const addThis = (num1, num2) => num1 + num2;
Back
What function can you use to round down to the nearest whole number?
Front
Math.floor() /number needs to be inserted /
Back
How do you give the following function the default value of Anonymous?
function greeting (name) {
return "Hello" + name;
}
Front
function greeting (name="Anonymous") {
return "Hello" + name;
}
*returns Hello Anonymous when no parameter is passed
Back
How do you prevent an object's data from mutating?
Front
Object.freeze();
Object.freeze is keyword
item that you are freezing goes in paren
Back
what is a do...while loop
Front
It does one pass of the code no matter what and then runs while a specified condition is true
var ourArray = [ ];
var i = 5;
do {
ourArray.push(i);
i++;
} while (i < 5);
Back
What function do you use to convert "083" to an integer?
Front
parseInt("083");
Back
What does Math.random() do?
Front
It's a function that generates a random decimal number between 0 and (inclusive) and not quite up to 1 (exclusive). **Note the capital M. It doesn't take any object. You can just say: return Math.random() /
Back
What does the .map( ) method do?
Front
Performs a function on an existing array and creates a new array from the results
Back
How can I write this shorthand:
const sayHello = function() {
return "hello";
}
Front
const sayHello = () => "hello";
Back
What is returned if parseInt() can't return a string?
Front
NaN
Back
What does the .filter() method do?
Front
Sorts an existing array by a specified requirement and creates a new array with the items that meet the requirement