Primitives (true/false), Variables, Data Structures, (Arrays, Objects (Brackets, Dot)), HOF, Flow Control (conditionals), Loops (for, while, for in), operators (math, logical, comparison), functions (parameters vs objects), scope, hoisting, callbacks, string concatenation, computer science (bigO), import/export functions, methods vs functions
A primitive is data that's immutable. In other words, data that can't be changed. Building blocks, Legos!
- Boolean -
true
orfalse
- Number - integers of floats
- String - text
- Undefined - value has not been defined
- Null - intentional absence of an object value (intentionally valueless)
- Symbol - (ES6)
Container to store a piece of data (values). Shortcut for storing data.
- Declare - using
var
- Naming - can't start with a number, can't have spaces, avoid symbols except
_
,$
, should be descriptive, use camelCase
- Arrays - container for primitives (and other data structures), accessed via index, maintain order
- Objects - key/value oarts, accessed via bracket or dot notation, not ordered
Procedural vs Functional
- Procedural - Javascript renders commands in order (set of instructions)
- Functional - break apart code/problem logically, generally separate state from behavior
Decides which things run based on specific conditions or loops
- if else
- if
- else if
- else
- Can be nested
Runs a piece of code for a certain amount of iterations
- Infinite Loop - loop that runs forever, you can run out of memory
- For
- While
- For in
- For of
- Do While
Range in which a varible can be accessed
- Local and Global (functional/lexical)
- Global - accessible everywhere; local accessible only when the function is invoked
function foo()
{
var test = 'some string';
function bar()
{
console.log(test);
}
}
The process by which the computer moves all variable declarations to the top of the applicable scope, so that it never encounters a variable it is unaware of. It's important to note that it does not move the variable assignment to the top of the page.
var foo = bar;
moves declarations var foo;
BUT NOT assignment var foo = bar;
function can take functions; the function thats passed into the higher order function is the callback
async - different code can run at different times
what happens is one function is dependent on another functions output
function testing()
{
return ing
}
function test()
{
return 'test' + arg;
}
var x =testing()
test(x)
used to join 2 or more strings
'test' + 'ing';
'test'.concat('ing')
you can also use +=
Big-O notation is how developers discuss the complexity of an algorithm as a way to understand how fast a program will run given it's input. Big-O notation deals with the worst case scenario for the algorithm. In other words, if the program may run quickly, but there is a chance it could take a long time given some input, then the Big-O runtime will deal with the longer case.
- o(n) linear, direclty realted to input size
- o(1) - constant time, bound by a constant, regardless of input size runtime remains the same
- o(n^2) - quadratic time, a nested loops
- A "flogaritihm" of a postiive number (n) represent by (log(n)) is the number of digits it has
- factorial - complexity is worse then quadratic
- (+) Addition
- (-) Subtraction
- * Multiplication
- (/) Division
- (%) Modulus
- (++) Increment
- (--) Decrement
- =
- +=
- -=
- *=
- /=
- %=
- == equal to
- === equal value and equal type
- != not equal
- !== not equal value or not equal type
- (>) greater than
- (<) less than
- (>=) greater than or equal to
- (<=) less than or equal to
- (?) ternary operator
- (&&) both statements are true
- (||) either statements are true
- (typeof) Returns the type of a variable
- (instanceof) Returns true if an object is an instance of an object type
a reusable code block that does one specific thing
- methods vs functions - method is a function that is contained within an object
- functions are first class citizens and can be used as arguments
- can have optional
- functions always return somethingl if not explicitly set, then it returns
undefined
A Parameter is a variable in the signature of a function declaration or definition:
function (parameter) {
}
An Argument is the value that gets passed to the function when calling it:
function(argument);
function greet() {
console.log("Hello, World!");
}
Type the name of the function
greet