JavaScript Flashcards
Front-End vs. Back-End Programming
Front-End
- Writing code that runs in the browser
- Faster to respond to user interaction
Back-End
- Writing code that runs on the server
- Slower to respond to user interaction
- Can be used for more than just user interaction
Where does the code written during front-end programming run?
The broswer
Where does the code written during back-end programming run?
The server
What are arrays used for?
Arrays are used to store multiple values in a single variable
An ordered collection of values
Each value is called an element
Each element has a numeric position in the array that is know as its index
Indexes are zero-based
JavaScript Types
Primitive Types - numbers, strings, booleans, null, undefined
Object Types - can apply to anything that’s not a primative type - collection of Keys and Values
what does array.push(“”) do?
Adds a element to the end of an array
what does array.pop(“”) do?
deletes an element from an array
what does array.concat(array2) do?
adds array and array2 together
Implicit Type Conversion
Performed automatically by JavaScript
11 + “ “ //output: “11” (number 11 converts to string “11”)
“15” + 15 //output: “1515” (concatenates “15” and 15 into a string)
“10” - “5”//output 5 (both strings convert to numbers)
Explicit Type Conversion
Performed explicitly in code:
String(25)//Output: “25” (number 25 converts to a string)
Number(“25”)//Output: 25 (string “25” converts to a number)
What are the three ways to declare a variable and how do they differ?
- var - globally scoped. define the variable outside of a function, can be declared and redeclared
- let - block scoped. must be defined within { } - can be updated but not redeclared
- const - cannot be updated or redeclared - constant
Expression vs. Statement
An expression is any code that can evaluate to a value
A statement is an instruction to do a certain action
Loose vs Strict Equality
Loose ==
Checks if two operands are equal (tries to convert the values to a common type before checking for equality)
Strict ===
Checks if two operands are equal (checks if the types are equal as well)
Iteration
Repeating a process (lines of code)
Helpful for processing every element in an array
The three clauses of a For Loop
- Initializer - runs before the loop
- Condition - a boolean expression that stops the loop when it’s false
- Afterthought - runs at the end of each cycle of the loop