# Scope

# Local Variables

function a {
    var x = 2;
    console.log(x);
}

// 2

function a {
    var x = 2;
}
console.log(x)
// undefined


1
2
3
4
5
6
7
8
9
10
11
12
13
14

These are called local variables. And they are available at their local scope.

# Global Variables

var x = 2;

function a {
    console.log(x)
}
// 2

if (true){
    var x = 2
    console.log(x)
}
//2 

if (true){
    var x = 2
}
console.log(x)
//2 This still works because getting declared inside `if` or `while` is available as a global variable. 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# var let const

  1. const is immutable, var and let is mutable.

  2. All three of them are Local/Global depending on where they are declared.

  3. When created inside if/else for while statements,

    • var is global.
    • let const is local
  4. Much safer and more predictable to use let instead of var. Very few scenarios require var to be used.

# var

  • variable declarations (and declarations in general) are processed before any code is executed, declaring a variable anywhere in the code is equivalent to declaring it at the top.
  • hoisting will affect the variable declaration, but not its value's initialization
  • If no value -> undefined. If no declaration -> ReferenceError
function do_something() {
  console.log(bar); // undefined
  var bar = 111;
  console.log(bar); // 111
}

// ...is implicitly understood as:

function do_something() {
  var bar;
  console.log(bar); // undefined
  bar = 111;
  console.log(bar); // 111
}

var x = y, y = 'A';
console.log(x + y); // undefinedA
//x and y are declared before any code is executed, but the assignments occur later
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# let

# const

# Strict mode

Default, non-strict mode referred to as sloppy mode. introduced in ECMAScript 5, is a way to opt in to a restricted variant of JavaScript. Support may differ per browser.

# Purpose

  1. Eliminates some JavaScript silent errors by changing them to throw errors.
  2. Can sometimes be made to run faster than identical code that's not strict mode.

# Usage

  1. Strict mode applies to entire scripts or to individual functions. It doesn't apply to block statements enclosed in {} braces.
  2. 'use strict'

# Converting mistakes into errors

Strict mode changes some previously-accepted mistakes into errors. JavaScript was designed to be easy for novice developers, and sometimes it gives operations which should be errors non-error semantics.

  1. Strict mode makes it impossible to accidentally create global variables.

  2. Any assignment that silently fails in normal code (assignment to a non-writable global or property, assignment to a getter-only property, assignment to a new property on a non-extensible object) will throw in strict mode.

  3. Delete undeletable properties throw (where before the attempt would simply have no effect).

    'use strict';
    delete Object.prototype; // throws a TypeError
    
    1
    2
  4. Function parameter names be unique

    function sum(a, a, c) { // !!! syntax error
      'use strict';
      return a + a + c; // wrong if this code ran
    }
    
    1
    2
    3
    4
  5. Forbids octal syntax. Novice developers sometimes believe a leading zero prefix has no semantic meaning, so they use it as an alignment device — but this changes the number's meaning!

    // ocatal syntax supported by browsers (but not by ECMAScript) 0644 === 420.
    //  In ECMAScript 2015 Octal number is supported by prefixing a number with "0o"
    var a = 0o10; // ES2015: Octal
    
    1
    2
    3

# Simplifying variable uses

  1. Strict mode prohibits with.

  2. eval of strict mode code does not introduce new variables into the surrounding scope.

  3. Forbids deleting plain names. delete name in strict mode is a syntax error

    delete x; // !!! syntax error
    
    1

# eval and arguments are simpler

I don't understand this part yet.

# Securing Javascript

Users can change JS and access private information. To censor access to forbidden functionality, many runtime checks must be done. But this has a considerable performance cost. A few strict mode tweaks, plus requiring that user-submitted JavaScript be strict mode code and that it be invoked in a certain manner, substantially reduce the need for those runtime checks.

  1. No longer possible to reference the window object through this inside a strict mode function
  2. fun.caller is the function that most recently called fun, and fun.arguments is the arguments for that invocation of fun. If fun is in strict mode, both fun.caller and fun.arguments are non-deletable properties which throw when set or retrieved.

# runtime

# Block

The block statement is often called compound statement in other languages. It allows you to use multiple statements where JavaScript expects only one statement. Commonly used in association with if...else (opens new window) and for (opens new window) statements.

  • Variables declared with var or created by function declarations in non-strict mode do not have block scope. Variables introduced within a block are scoped to the containing function or script, and the effects of setting them persist beyond the block itself.

  • By contrast, identifiers declared with let (opens new window) and const (opens new window) do have block scope

  • const

    const c = 1;
    {
      const c = 2;
    }
    console.log(c); 
    // logs 1 
    // and does not throw  SyntaxError: Identifier 'c' has already been declared
    // because it can be declared uniquely within the block
    
    1
    2
    3
    4
    5
    6
    7
    8

# Window object

# This

t

# call

# Hoisting

Variables declared using var are created before any code is executed in a process known as hoisting

# Destructuring assignmnet

let a, b, rest;
[a, b] = [10, 20];

console.log(a);
// expected output: 10

console.log(b);
// expected output: 20

[a, b, ...rest] = [10, 20, 30, 40, 50];

console.log(rest);
// expected output: Array [30,40,50]
1
2
3
4
5
6
7
8
9
10
11
12
13

# Hash and Rainbow

https://security.stackexchange.com/questions/379/what-are-rainbow-tables-and-how-are-they-used

https://cryptii.com/

https://www.youtube.com/watch?v=G2_Q9FoD-oQ

https://www.youtube.com/watch?v=V4V2bpZlqx8

# DB

https://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

# Gulp

# GraphQL

# TypeScript

Last Updated: 3/1/2021, 9:19:08 PM