Section 1

Preview this deck

3 Scopes

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (24)

Section 1

(24 cards)

3 Scopes

Front

Global scope Local Scope/Function scope Block scope(Introduced in ES6)

Back

reduce

Front

Reduces the array to a single value. Example = flattening arrays: var arr = [[1, 2], [3, 4], [5, 6]]; var flattenedArray = arr.reduce((accumulator, currentValue) => { return accumulator.concat(currentValue); }, []); // returns [1, 2, 3, 4, 5, 6]

Back

Closure

Front

An inner function that has access to the outer function's variables—scope chain. It has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function's variables, and it has access to the global variables.

Back

Data types copied by Value

Front

AKA Primitive types: Boolean, null, undefined, String, and Number const name = 'chelsea'; const name2 = 'chelsea'; console.log(name === name2); // true

Back

filter

Front

Filter elements from an array. Returns the filtered array. var words = ["tiger", "toast", "boat", "tumor", "track", "bridge"] var newData = words.filter((elem) => { return elem.startsWith('t') && elem.endsWith('r') ? true:false; }); // returns ["tiger", "tumor"]

Back

call vs apply

Front

both methods expect a thisArg as the first argument. This is the argument that gives the function a context; it determines the value of the JavaScript keyword this inside the function that is called or applied. The single difference is that the call method requires that arguments are specified separately; the Apply method takes them as an Array.

Back

map

Front

For use on an array. It is a function that: 1. Takes an array and a function 2. Applies the function to every element in the array 3. Keeps track of the results of each successive function call 4. Returns a new array containing these results myArray.map(myFunction);

Back

undefined vs null vs undeclared

Front

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object. Undeclared has not been declared with 'var', 'let', or 'const'

Back

Javascript Class syntax

Front

class User { constructor(name) { this.name = name; } sayHi() { alert(this.name); } } let user = new User("John"); user.sayHi();

Back

scope

Front

the accessibility of variables, functions, and objects in some particular part of your code during runtime. common principle of computer security is that users should only have access to the stuff they need at a time.

Back

Javascript Prototype Class

Front

function User(name) { this.name = name; } User.prototype.sayHi = function() { alert(this.name); } let user = new User("John"); user.sayHi();

Back

object literal

Front

object created using {} var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

Back

switch statement

Front

switch(expression) { case x: code block break; case y: code block break; default: code block }

Back

IIFE

Front

Immediately-Invoked Function Expression (function () { // private scope })();

Back

Module Pattern

Front

var Module = (function() { function privateMethod() { // do something } return { publicMethod: function() { // can call privateMethod(); } }; })(); Module.publicMethod(); // works Module.privateMethod(); // Uncaught ReferenceError: privateMethod is not defined **begin private functions with an underscore

Back

JS primitive data types

Front

5 data types that are copied by value: Boolean, null, undefined, String, and Number const name = 'chelsea'; const name2 = 'chelsea'; console.log(name === name2); // true

Back

Strict Mode

Front

When a function is called in Strict Mode, the context will default to undefined.

Back

apply vs call vs bind

Front

You can use call()/apply() to invoke the function immediately. bind() returns a bound function that, when executed later, will have the correct context ("this") for calling the original function.

Back

hoisting

Front

The JavaScript interpreter's action of moving all variable and function declarations to the top of the current scope. However, only the actual declarations are hoisted. Any value assignments are left where they are, including function expressions (var myFunc = function() {}).

Back

callback

Front

A callback is a function that is to be executed after another function has finished executing

Back

why do we need callbacks?

Front

JavaScript is an event driven language. This means that instead of waiting for a response before moving on, JavaScript will keep executing while listening for other events. You can't just call one function after another and hope they execute in the right order. Callbacks are a way to make sure certain code doesn't execute until other code has already finished execution.

Back

while loop

Front

repeats a sequence of statements either as long as or until a certain condition is true var text = "" var i = 0; while (i < 10) { text += "The number is " + i; i++; }

Back

do-while loop

Front

This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. var text = "" var i = 0; do { text += "The number is " + i; i++; } while (i < 10);

Back

try/catch block

Front

try { updateUI(result["posts"]); } catch(e) { logError(); flashInfoMessage(); }

Back