Javascript Essentials Flashcards
memorize terms
Function Overloading
the ability to create multiple functions of the same name with different implementations
whitespace
invisible characters that create literal ‘space’ in your written code
Immediately Invoked Function Expressions
a JS expression that runs as soon as it’s defined
Array
a variable that holds many values insdie of it []
arguments
the parameters that you pass to a function
mutate
to change a value
immutable
cannot be changed
JSON
Javascript Object Notation
First Class Functions
everything you can do with other types you can do with functions, assign them to variables, pass them around, create them on the fly. function names can be anonymous. Functions are an object whose code happens to be the properties on that object.
First Class Functions = Functional Programming
Function expression
a unit of code that results in a value. It doesn’t have to save a variable. Usually created on the fly.
function statement
a function that just ‘does work’
Namespace
a container for variables and functions, typically to keep variables and functions with the same name seperate.
Primitive Property
number, boolean, string
Object Property
Object within Object
Function Method
a function that is connected to an object
Operator
a special function that is syntactically (written) differently.
Precedence
which operator gets called first (PEMDAS)
Associativity
what direction operator functions get called in L->R R->L
coercion
converting a value from one type to another
array.filter()
creates a new array with all elements that pass the test implemented by the provided function.
array.map()
creates a new array with the results of calling a provided function on every element in the calling array
array.reduce()
method executes a reducer function (that you provide) on each element of the array, resulting in a single output value. The reducer function takes four arguments:
Accumulator (acc) Current Value (cur) Current Index (idx) Source Array (src)
Your reducer function’s returned value is assigned to the accumulator, whose value is remembered across each iteration throughout the array and ultimately becomes the final, single resulting value.
trim
method removes whitespace (spaces, newlines, tabs, and similar) from the start and end of a string
padstart()
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string.
string.length()
accessing individual characters in a string looks like accessing array elements. It returns count of total number of characters. The length of java string is same as the unicode code units of the string.
rest parameters (…Args)
it can useful for a function to accept any number of arguments. The rest parameter syntax allows us to represent an indefinite number of arguments as an array.
array.indexOf()
method searches through the array from the start to the end and returns the index at which the value was found, or -1 if not found.
array.slice()
takes the start and ending indexes and returns an array that has only the elements between them. The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.
array.concat()
The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
array.splice()
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements
indexOf()
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
lastIndexOf()
The lastIndexOf() method returns the index within the calling String object of the last occurrence of the specified value, searching backwards from fromIndex. Returns -1 if the value is not found.
searchValue: A string representing the value to search for. If searchValue is an empty string, then fromIndex is returned.
Takes an optional second argument that indicates where to start searching.
array.push() & array.pop()
add and remove elements at the end of an array.
array.shift() & array.unshift()
add and remove elements at the start of an array.
array.includes()
The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
==
compares by identity, it will produce true only if both objects are precisely the same value.
stack
a data structure that allows you to push values to it, and remove them as well.
properties
all .js values have properties, exception is null and undefined
delete
operator unary, when applied to an object property, will remove the named property from the object
object
arbitrary collections of properties
pure function
a specific kind of value producing function that not only has no side effects but doesn’t rely on side effects from other code. -> doesn’t read global bindings whose value might change.
recursion
a function that calls itself until a base case is reached and some value is returned.
closure
being able to reference a specific instance of a global binding in an enclosing space, a function that references bindings from local scopes around it.
function definition
a regular binding where the value of the binding is a function.
local binding
created for function parameters or declared inside a function, can be referenced only by that function.
enumerable
any property you add to an object (not those that are inherited) can be iterated over.
pseudoclassical instantiation
prototype in JS is just a property on a function that points to an object, or a property that every js function has that points to an object
object.create
allows you to create an object that will delegate to another object on failed lookups. consults another object to see if that object has the property.
prototype
every function in Javascript has a prototype property that references an object, allows us to share methods across all instances of a function.
functional instantiation
encapsulate logic inside a function that can be invoked when creating new instances of an object. Called a constructor function, since it is possible for constructing an object.
dynamic typing
you don’t tell the engine what type of data a variable holds, it figures it out while your code is running.
Syntax Parser
a program that reads your code and determines what it does and if its grammer is valid.
Class
Classes are in fact “special functions”, and just as you can define function expressions and function declarations, the class syntax has two components: class expressions and class declarations.
constructor method
A JavaScript class is a type of function. Classes are declared with the class keyword. The constructor method is a special method for creating and initializing an object created with a class. There can only be one special method with the name “constructor” in a class. A SyntaxError will be thrown if the class contains more than one occurrence of a constructor method.
null
intentionally having no value
undefined
a declared variable that hasn’t been assigned a value yet
boolean
true or false
Symbol
a unique value that’s not equal to any other value. Note, this is an ES6 feature that never really took off, so don’t worry about it for now.
string
a series of characters (letters, numbers, spaces, symbols, etc.) wrapped in quotes
Object
Objects in JavaScript, just as in many other programming languages, can be compared to objects in real life. Objects are standalone entities, with properties stored in key/value pairs. Compare it with a person, for example. A person is an object, with properties. A person has a race, a date of birth, a weight, a height, an eye color, etc. The same way, JavaScript objects can have properties, which define their characteristics.
array
Used to store multiple values in a single variable. Similar to a list. Technically, arrays are objects in JavaScript, but we’ll dive into that more in second half of the pre-course.
escape sequences
ways of formatting characters in strings.
Anytime JavaScript sees a () inside of a string, it knows that the following character has a special meaning. Here is a list of some of the most common escape sequences:
\' => single quote \" => double quote \\ => backslash \n => newline \r => carriage return \t => tab \b => backspace \f => form feed
template literals
Template literals are a special type of string that make creating complex strings so much easier. Template literals are created by surrounding text between opening and closing backticks (``). Inside a template literal, you’re able to refer to variables or execute code by using ${}
The exponentiation operator (**)
The exponentiation operator (**) raises the first number to the power of the second number.
== and !=
is loosely equal/not equal to
=== and !==
is strictly equal/not equal to
parseInt()
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
hoisting
variable and function declarations are put into memory during the compile phase, but stay exactly where you typed them in your code.
free variable
a variable that is outside a function but you have access to.
string.substring()
The substring() method returns the part of the string between the start and to but not including the end indexes, or to the end of the string if only one index given.
array.slice(i, i)
method returns a shallow portion of an array object into a new array object from beginning endex to ending index, or to end of array if index not provided.
array.unshift(things to add)
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.