JS Essentials Flashcards
Notes from Lynda.com JS Essentials (55 cards)
Are variables uppercase or lowercase
Start with lowercase, then use camelcase
Are objects and constants uppercase or lowercase
Objects and classes start with uppercase, constants are all caps
what do you end each statement with
a semicolon
how do you set a variable as a string
var sting=”string full of words”
How do you deal with quotation marks in a string when declaring a variable
Escape the quotes var escQuote = "quotes can be \"escaped\"."
how do you find the data type of a variable
console.log(typeof variableName);
what are the data types of variables
numeric, string, bollean, null, undefined, symbol
Math:
how do you increment a variable by 1?
subtract by 1?
var a;
a++;
or
a–;
Math: var a=1; what are the results of the following: console.log (a); console.log (++a); console.log (a++);
console. log (a); produces 1
console. log (++a); produces 2
console. log (a++);
var a = 4; var b = "5"; var sum = a + b; console.log (sum);
45
because 5 is a string it assumes you are combining strings
var a = 4; var b = "5"; var subt = a-b; var mult = a*b; var div = a/b;
console.log (subt); -1
console.log (mult); 20
console.log (div); .8
because you are not using + it assumes 5 is a number
var a = 5; var b = '5'; var theNumbersMatch;
if ( a ==b ){ theNumbersMatch = true; } else { theNumbersMatch = false; } console.log ("the numbers match: " + theNumbersMatch);
True because the string of 5 is 5
How do you write
if a equals b and c equals d
if a equals b or c equals d
if a equals b xor c equals d
if (a == b && c == d) {}
if ( a == b || c== d) {}
if (( a == b || c == d) && (( a == b) ! = (c ==d)) {}
//AND - both a and b are true //OR - either a or b are true or BOTH //xor if a equals b xor c equals d (not both)
rewrite the following as a ternary operator if ( a==b){ console.log("match"); } else { console.log ("no match"); }
a == b ? console.log (“match”) : console.log(“no mactch”);
var pens = [“red”, “blue”, “green”, “orange”];
how do you find the orange based upon its position?
how do you change the value in the array by referring to its position?
var fourthPen = pens[3]; console.log (fourthPen);
pens [3] = “purple”;
var pens = [“red”, “blue”, “green”, “orange”];
how do you find the length of the array?
console.log (“array length:”, pens.length);
var pens = [“red”, “blue”, “green”, “orange”];
How do you reverse the array?
console.log(pens.reverse());
var pens = [“red”, “blue”, “green”, “orange”];
how do you return the first value of the array?
console.log (pens.shift());
var pens = [“red”, “blue”, “green”, “orange”];
how do you add values to the front of the array
pens.unshift(“purple”, “black”);
var pens = [“red”, “blue”, “green”, “orange”];
how do you remove the last value of the array
console.log (pens.pop());
var pens = [“red”, “blue”, “green”, “orange”];
how do you add values to the end of the array
pens.push (“pink”, “prussian blue”);
var pens = [“red”, “blue”, “green”, “orange”];
How do you take blue away from the array?
pens.splice (1,1);
var pens = [“red”, “blue”, “green”, “orange”];
how do you make a copy of an array?
var newPens = pens.slice();
var pens = [“red”, “blue”, “green”, “orange”];
how do you return the values of the array in a comma separated list?
var arrayString = pens.join(separator); console.log('string from array: ', arrayString);