Used in frameworks/ libraries like jQuery
Wrap code for the framework inside of IIFE to protect scope of its variables and to make sure everything is executed without the user having to do anything
Back
Asynchronus Operations
Front
make the code execute in a way that doesn't read top to bottom
Ex: adding a timeout to delay by 3000 seconds
Back
Object Methods
Front
Actions that can be performed on an object
Are stored in objects as function definitions
Back
splice();
Front
Method for splitting arrays. destructive function bc it changes content of the input array
Removes existing elements or adds new ones
Back
JS Object Constructors
Front
A blueprint for creating many objects of the same "type"
Objects of the same type created by calling constructor function with "new" keyword. Doesn't have to have "constructor" in name when declared.
Looks like a function but with Capital first letter name
Back
.sort(); method
Front
Sorts elements in an array
Back
Lexical scoping
Front
Uses the location where the variable is declared within the source code to determine where that variable is available. Nested function have access to variables declared in outer scope
Back
3 states of promises
Front
pending: initial state before operation begins
fulfilled: specific operation was completed
rejected: operation didn't complete =error thrown
Back
Object.seal()
Front
Seals an object
Prevents new properties from being added and existing non-configurable
Values of present properties can be changed
Back
slice();
Front
Method for splitting arrays. Non-destructive-returns a new copy
Normally used in function programming to avoid side-effects
Back
Promises
Front
We can defer execution of a code block until an async request is completed: so that other operations can run without interruption
Back
Hoisting
Front
Variables and function declarations are moved to top of scope. Declaration is hoisted not initialization.
Back
Arguments
Front
Real values passed to the function. Take place of parameters
Back
Function Return
Front
when reaches return statement, will stop executing. Will compute a return value
Back
For loop code
Front
var hello = "hello"
for (var i = 0; i < 50; i++) {
console.log(hello);
}
Back
Arrow functions
Front
Use less code than normal functions
don't have their own "this": not good for defining object methods
Are not Hoisted - must define before use
Back
JS Objects
Front
are variables too, but they can contain many values.
Values are written as name:value pairs
Or Property: Property Value
Access object properties with property name
Back
.map();
Front
JS Method
Takes 2 arguments (callback and optional context)
Callback runs for each value in array and returns each new value in resulting array
Back
Call() / apply ()
Front
JS Method
Invoke the function immediately
Back
Callback Functions
Front
Function simply accepts another function as an argument, the contained function is a callback
.map() method iterates through array and accepts callback function Return that decides how elements are manipulated
Back
Local variables
Front
Variables declared inside the JS function- local to the function
Back
Class Expressions
Front
Another way to define a class
Can be named or un-named
Constructor method can only be used once inside a class
Can use "super" keyword to call the constructor of the super class
Back
.reduce();
Front
JS Method
passes the callback from one element of array to other
ex: accumulator adding up years of experience from different element members of array
Back
Parameters
Front
Variables listed as part of the function definition inside ( ).
Back
Anonymous Functions
Front
Created using the function operator not declaration (no function name)
could use var name = function(){
Back
JS Built in constructor objects
Front
new String();
new Array();
new Date();
Back
Objects.freeze();
Front
Freezes an object. Can no longer be changed
Prevents new properties from being added, deleted, or changed
Also prevents prototype from being changed
Back
Invocation
Front
When event occurs (button click)
When called by JS code
Automatically (self Invoked)
Back
bind()
Front
JS Method
used when function needs to be called later in certain events
returns a bound function that when executed later will have correct "this"
Back
JS Function
Front
Block of code designed to perform a task
Executed when invoked/called
Defined with function keyword, followed by name, followed by ()
Back
Global Variables
Front
Declared outside function: has global scope
Back
Regular Expression
Front
Sequence of characters that form a search pattern
Used for text search and tech replace operations
2 string methods: search() and replace()
Back
var
Front
Always function scoped
Can be reassigned & redeclared
Global scope: declared outside a block
Local scope: declared inside
Back
Closures
Front
Combination of a function and lexical environment within which that function was declared
(Basically being able to use instances/ variables not completely intuitive to be available because of scope)
Back
let
Front
No hoisting
block scoped
cant be reassigned or redeclared
the strictest one
Back
Destructuring:
Front
new feature in JS ES6 allowing destructure of properties of an object
And values in array
Back
Arrays
Front
Technically special type of Objects. Arrays use numbers to access its "elements" [ ]. Can have objects, functions, and arrays inside an array
Back
Why functions?
Front
Use same code many times with different arguments to produce different results
Back
sub classes with "extends"
Front
The "extends" keyword is used in class declarations and expressions to create child class of another class
Classes can't extend non-prototype objects
Back
"this" inside an object
Front
refers to the "owner" of the function
Back
Bubbling
Front
When an event happens in an element, it first runs the handlers in it, then in its parents, then all the way up.
ex: nested alerts in html
Back
JS classes
Front
special functions with 2 syntax components (class expressions & declarations)
To declare use the class keyword and name of class
Back
block scoped
Front
A local scope created from any kind of block including:
function blocks, if statements, for/while loops.
ex: const and let
Back
3 methods to split an array
Front
splice(); slice(); split()
Back
.length property
Front
returns number of elements. Used in for loop examples
Back
.filter();
Front
JS Method
grab certain elements from the array
ex: faction:rebels
Back
Prototype Inheritance
Front
All JavaScript objects inherit properties and methods from a prototype:
Date objects, Array objects, and Person objects inherit from Object.prototype.
Back
prototype property
Front
The JavaScript prototype property allows you to add new properties to object constructors:
Person.prototype.nationality = "English";
(functionName.prototype.newkeyword: value;
Back
const
Front
block-scoped
values cant be modified or changed
Arn't hoisted
Must be declared and initialized at the same time
Considered "mutable" (values can be changed) because can modify properties of an object declared with const
Back
split();
Front
Method for splitting arrays. Splits string by separator into new array
-ex: separates words in "hello world"
Back
Section 2
(12 cards)
JS Value vs Reference
Front
Types copied by value: primitives:
Null, undefined, number, Boolean, String
Types copied by reference: Objects:
Object, Array, Function
Back
3 types of errors
Front
Syntax Errors: missing or wrong syntax
Ex: missing close parenthesis
Runtime Errors (exceptions): when code executed, compiled
Ex: calling method that doesn't exist
Logical Errors: flaw in logic that leads to unexpected results/behavior
Back
error handling patterns
Front
Try...catch...finally: response if an error is thrown
Only catches logical and runtime errors
Throw: user defined exceptions
When encountered code will stop executing
Back
Integration Testing
Front
testing whole component/application
Make sure everything is working together
Back
JavaScript Variables (6)
Front
Numbers
Strings
Objects
Arrays
Functions
Back
What is JavaScript?
Front
Client-side Programming Language
the Programming Language for the Web
can update and change both HTML and CSS
can calculate, manipulate and validate data
Back
User-Interface
Front
test app by controlling browser -not inner workings
Go crazy doing anything possible on the webpage and see what breaks (unpredictable behavior)
Back
Unit testing
Front
70% of all testing
testing smallest bits of functionality
ex: testing routes from the different resources ex:router.post in user.js lines
Back
Testing Pyramid
Front
Unit Testing -> Integration -> User-Interface
Back
Why JS?
Front
JavaScript allows you to build interactive websites
JavaScript usage has now extended to mobile app development, desktop app development, and game development.
Essential web technology along with HTML and CSS
Back
Testing Frameworks
Front
tests spot error and tell you where it failed
Give you functionality to do all types of testing
ex: Jest and Mocha