ALL Flashcards
7 data types
numbers, strings, boolean, objects, arrays, null, undefined
strings
words
what is interpolation
back ticks ``
interpolation operators
${}
how to combine text
“word” + “word”
Boolean
conditional statement if this do this
what is falsey data
false, null, undefined,null, 0, NaN, empty “ “
Strict Equality operators
===
strict inequality operators
!==
3 logical operators
Not (!), And (&&), Or(||)
tenary expressions
if then statement
tenary structure
value/condition ? return if true : return if false
Variable Declaration
a statement: const cat=”rose”
2 code statements
Selection and Repetition
Selection statement
if, else, else if
if statement structure
if (condition) {
thing to do if true
}
else statement structure
if (condition) {
thing to do if true
} else {
thing to do if false
}
if else
if (condition) {
thing to do if true
} else if (condition 2) {
thing to do if condition 2 is true}
switch statement
alternate for conditional statement with multiple conditions again same value
switch statement structure
switch (expression) {
case value1:
//Statements executed when the
//result of expression matches value1
[break;]
case value2:
//Statements executed when the
//result of expression matches value2
[break;]
…
case valueN:
//Statements executed when the
//result of expression matches valueN
[break;]
[default:
//Statements executed when none of
//the values match the value of the expression
[break;]]
}
Default
set of statements to run after all of the switch statement cases have been checked
Break
stop switch statement from continuing to look at case statements once it finds a match
logging
process of printing information about the program as it runs. example: console.log
Repetition statement
while
while loop structure
while (condition) {
do if condition is true
}
increment/decrement operators
add ++ or +=
subtract – or -=
terminate while loop naturally
let count = 0
while (count <3){
return ${count};
count = count++
}
function structure
function functionName (parameter) {
code to run when function is called
}
parameter
placeholder for argument that will get passed through
return
statement ends function execution and specifies a value to be returned to the function caller
parseInt()
turns number inside “ “ from strings into numbers
2 Data Structures
Array and Objects
Arrays
collections of values in ordered lists
Elements
individual pieces of data inside an array
index
number that identify each element in array
object
list of values using key and value
array structure
const arrayName = [
data, data
]
.length
finds the number of elements in an array
what is the index of the first element in an array
0
how to update an array
arrayName[index] = “no element”
destructive mutability
methods update or mutate the object
nondestructive mutability
doesn’t change the value
Array methods
ways to add, remove and change elements
add elements destructively to array
.push() and .unshift()
add elements to array non destructively
spread operator …
.push ()
add to end of array
.unshift ()
add to beginning of array
spread operator
… creates a copy of the original array to be changed l
structure to use spread to add to beginning of array
const newArray = [“new element”, … oldArray]
structure to spread to add to end of array
const newArray = [ … oldArray, “new element”]
remove elements from aray
.pop(), ,shift(), .slide()
.pop()
removes last element destructively
.shift()
removes first element destructively
.slice ()
makes copy of removed indexes in parameter
.slice () strucutre
array.slice(index to start number after this index will be removed, index to end slice)
.splice structure
array.splice(start index, delete count, element to add)
object structure
const objectName = {
key 1: value 1,
key 2 : value 2,
};
access value in object
dot notation, bracket notation
dot notation
objectName. key
bracket notation
objectName[“key”]
object.keys ()
pulls all of the keys at the top level of object
What does object.values return?
returns the object values
adding property to object with dot notation
object.key = new value
adding property to object with bracket notation
object [“key”] = new value
structure to use spread to add to object
function nondestructive (object, key,value) {
const newObject = {…oldObject};
newObject[“key”] = value;
return newObject;
}
remove a property
delete object.key
debugging in Node
add debugger keyword where you want a breakpoint
for loop structure
for (initialization; condition; iteration) {
loop body
}
initialization
counter values. let age=30
condition
expression evaluated before each pass through. age<40
iteration
what happens at the end of each loop through. age++
loop body
code that runs on each pass through
while loop
while (condition) {
loop body
}
looping
process of executing a set of statements repeatedly until a condition is met