General Flashcards

1
Q

Compiler

A
  • Converts code from one language to another
  • Generally converts from a higher level language to a lower level language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Linker

A
  • combines the various files produced by compiler
  • generates executable code that computer actually interacts with
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

statement vs expression

A
  • expression is a unit of code that returns a value
    • a = 1 (returns a)
    • a == True
  • statement is a unit of code that just does work
    • doesn’t return a value
    • if statement, for loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Lexical Environment

A
  • The location of code within a program
  • For example, a variable might sit lexically inside a function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Object

(in Javascript)

A
  • A collection of key/value pairs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Execution Context

A
  • The environment/state of a function that is created by involking a function
  • A new execution context is created every time a function is invoked
  • Includes
    1. the variables in scope
    2. function arguments
    3. the this variable (the context)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Lexical Scoping

A
  • Also called compile-time scoping
  • The scope of all variables is determined at compile time, by the location of the variables
  • Basically normal scoping
  • Most languages (including JS) have lexical scoping
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Hoisting

A
  • Process of allocating memory for variables and functions during the compilation phase
  • Or, the process of “moving declarations” to the top of the current scope

Three scenarios during compilation phase:

  1. Variable Names
    • Are put into memory
    • Declarations are hoisted, but variables are set to undefined
    • Naked variables (variables without a keyword) are not hoisted
  2. Functions Declarations
    • Are put into memory
    • They are hoisted, and can be used before being explictly defined
  3. Function Expressions
    • Names are put into memory, set to undefined
    • Using function expressions before defining them throws a TypeError
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

undefined

A
  • a primative type
  • a special value that is automatically assigned to variables upon declaration
  • Indicates that a variable has not been given a value yet
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

single threaded

A
  • One command is being executed at a time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

synchronous

A
  • Tasks are completed in order
  • JavaScript itself is synchronous, but it can make callback requests and create asynchronous behavior
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

asynchronous

A
  • asynchronous code allows you to start something now and finish it later
  • does not have to complete tasks in order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

let

A
  • Variable keyword
  • New to EC6
  • Allows you to create variables whose scope is just a block
    • things with curly braces
    • if statements, for loops, etc.
  • let variables are hoised, but…
    • are hoisted: replace any reference to variables in outer scope
    • but, using let variable before initialization throws a reference error, as opposed to undefined with var
  • Syntax

Example (in an if statement):

console.log(c)

let c = 100

*Throws a reference error, even if c was already defined outside of block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

const

A
  • variable keyword
  • new to ES6
  • like let, they create block-scoped variables
  • however, variables cannot be reassigned
    • primative variables cannot be changed
    • variables set to objects can be changes, but not reassigned
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Event Handling

in JavaScript

A
  • JS only processes events when execution stack is empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

dynamic typing

A
  • type of variable is determined at runtime (versus compile time)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Primative Types

(JavaScript)

A
  • a built in data type
  • data that is not an object and has no methods
  • all primitives are immutable
  • all primatives (except null and undefined) have object wrappers

6 Primative Types

  1. undefined
  2. null
  3. boolean
  4. number
    • only one ‘number’ type in JS
    • it’s a floating point number
  5. string
  6. symbol
    • New to ES6
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

operators

A
  • operators are basically normal functions with special syntax
19
Q

infix notation

A
  • notation that places operators between operands
  • ex: +, -, <, >
20
Q

associativity

A
  • order in which functions (operators) are invoked when functions have same precedence
  • either left-to-right or right-to-left
  • ex: + is left-to-right, but = is right-to-left
21
Q

coersion

A
  • when JS implicity converts a variable from one data type to another
22
Q

== vs ===

A
  • double equals
    • tests for loose equality (abstract equality)
    • uses type coersion
  • triple equals
    • tests for strict equaliy
    • does not use type coersion
    • should always default to triple equals
23
Q

giving default value to parameters

A
  • syntactic trick to give parameter default values in functions
  • Logical Or the variable with another value
  • This will initialize a variable if it is undefined
  • ex: name = name || ‘Greer’
24
Q

JSON vs JS

A
  • All JSON is valid JS
  • But not all JS is valid JSON
  • JSON requires double quotes around keys and values
  • And doesn’t allow functions as values
25
first class citizens | (first class functions)
* first class citizens are types/objects that support all the operations that other types support * first class functions are functions that are first class citizens * functions that can do everything that other types can * assign them to variables * pass them as arguments * create them on the fly
26
pass by value pass by reference
_2 situations_ * b is set to a (b = a) * a is passed to a function b _pass by value_ * b makes its own copy of the data and places it somewhere else in memory * primitives are passed by value in JS _pass by reference_ * b simply points to the same location in memory that a does * causes one object to have two names * objects passed as parameters can be changed by function they were passed to * objects (including functions) are passed by reference in JS
27
arguments object
* special variable created in each function automatically during compilation phase * a list of all parameters that were passed to a function * list is array-like (an object with array like properties)
28
Immediately Invoked Function Expressions (IIFE)
* also known as self-invoking anonymous functions * programming idiom that allows functions to invoke themselves * IIFE's have their own scope and execution context _2 situations_ * **function expressions** 1. Simply add invokation parens after writing expression 2. Arguments can go in invokation parens 3. But you can also wrap function in parens if you want, a la function declarations 4. Function can be named or anonymous * **function declarations** 1. Wrap function in paratheses to turn it into expression 2. And then place invokation parens at end of new expression * Can place parens inside or outside of wrapper * (function() { … })(); ⇔ (function() { … }()); 3. Arguments go in parens 4. Function can be named or anonymous
29
closures
* The ability of a function to remember and access its lexical scope even when invoked in a different lexical environment * All functions have this ability automatically * Often used when an outer function returns an inner function * That inner function can continue to use varaibles local to the outer function even after the outer function as been run and completed * It can even change variables in the bygone lexical scope and access these changes
30
callback function
* a function that gets passed to another function and triggered by an event
31
***this*** keyword
* ***this*** binding is automatically defined in an execution context _4 situations_ 1. Default Binding * By default, ***this*** is always bound to the global object (even when function is defined within another object) * Or bound to undefined in "strict mode" 2. Invoked with an object * The *t**his*** value becomes the object that involked a function * ex: obj1.func() --\> the ***this*** inside func's execution context is now obj1 3. If **new** keyword is used * ***this*** binding is new, empty object * even true even after using bind, call or apply 4. arrow functions * ***this*** bindng equals whatever ***this*** was in lexical scope * even if function is involked with an object * even after using bind, call or apply
32
bind
* Method automatically avalable to every function * Duplicates a function with permanent parameters * Used to recreate function with a new, fixed value of ***this***, as well as fixed values for other args * _Syntax_ var myFuncTwo = myFunc.bind(newthis, arg1, arg2)
33
call, apply
* Automatically built in to every function * Allow you to manually set value of ***this*** when invoking a function * Both can be used on IIFEs * Sytax of each differs slightly _call Syntax_ myFunc.call(ctx, var1, var2) * separate arguments with commas [call ⇒ commas] _apply Syntax_ myFunc.apply(ctx, [var1, var2]) * include additional parameters in an array [apply ⇒ array]
34
strict mode
* Tells engine to implement extra, stricter rules when processing code * Not all engines implement strict mode the same way * Must go at top of execution context (top of file, top of function) * Rules include: * does not allow global object to be bound to ***this*** * does not allow naked variables * cannot name a variable "arguments" _Sytanx_ * "use strict";
35
inheritance
* one object gets access to the properties and methods of another object
36
For Loops in JavaScript
_4 Ways_ 1. for loop (normal) 2. for...in * loops through all the immediate keys in an object * not ideal for arrays; will return any arbitrary properties added to array object * for (key in obj) { } * for inoperative objects 3. for...of * for loop designed specifically for iterables (Arrays, Strings, Maps, Sets) * Loops over elements, but skips arbitrary key/value properties * for (val of arr) { } * for affirmative arrays 4. Array.prototype.forEach * part of array prototype * runs some function using elements in array in input * arr.forEach(callback(current, index, array), theThis) * passing the *this* binding is optional
37
Removing elements from an array
_3 Approaches_ 1. Array.prototype.pop() 1. Removes the last element in the array 2. Changes array 2. Array.prototype.shift() * Removes the first element of the array * Changes array 3. Array.prototype.splice(start, delNum, item1, item2) * Removes delNum # of elements starting from index 'start' * If delNum is ommitted, removes all elements from (and including) start to end * Will insert additional arguments after delNum if included
38
hasOwnProperty
* part of the Object prototype * returns true if a property is defined on the object itself (rather than prototype chain) * myObj.hasOwnProperty(prop)
39
typeof instanceof
* typeof * tells you what type something is * NOTE: typeof null is object, widely considered to be a bug * instanceof * tells you if an object is an instance of a constructor * myObj instanceof myFunc * returns True if myObj's \_\_proto\_\_ (or any of its parents \_\_proto\_\_'s) points to myFunc.prototype
40
[[]] double square brackets
* double square brackets denotes that an "internal property" * property is hidden or read-only * cannot be accessed/edited by the user * however, may be exposed through another method/property * ex: * [[Prototype]] and \_\_proto\_\_
41
Transpile
* A specific version of compilation * To transform code from one language to another language with a similar level of abstraction
42
TypeScript
* a version of JavaScript that is class-based and statically typed
43
web workers
* a javascript process that has been delegated ot the background * does not interfere with performance of the webpage * doesn't have access to document, cannot do DOM manipulation * workers can spawn other workers
44