From IT Skills
Jump to: navigation, search

Javascript is not even a true programming language. It is a mess created by Netscape in a week! It is the worst language ever, and yet we run the world wide web on it! There are many modern and wonderful languages that the W3C could approve tomorrow morning as a new web standard... Mobile apps, videogames, video editing… in all those fields people are using SVG. Not mixed with HTML, Javascript and CSS. Just SVG.

The easiest way to figure out statements in JavaScript is to look for the semicolon sign ; ... Statements in a programming language can contain expression... Expressions: function class /pattern/i () // grouping... function() {}

The execution context is composed of the activation object (the function's parameters and local variables), a reference to the scope chain, and the value of this. The call stack can be thought of as an array of execution contexts.

The environment in which your code is running is Execution context.

functions in JavaScript form closures. A closure is the combination of a function and the lexical environment within which that function was declared... functions are nested... Closures are useful because they let you associate data (the lexical environment) with a function... Emulating private methods with closures... Every closure has three scopes: Local Scope (Own scope) Outer Functions Scope Global Scope

Variables, scope, environment[edit]

With strict mode, you can not, for example, use undeclared variables.

Глобальными называют переменные и функции, которые не находятся внутри какой-то функции. То есть, иными словами, если переменная или функция не находятся внутри конструкции function, то они – «глобальные».... Объект window одновременно является глобальным объектом и содержит ряд свойств и методов для работы с окном браузера

With ES#6, JavaScript introduced the let keyword and block scope.

Variables defined with var inside a function scope .. don’t leak out of that scope... However, when you define variables with var in a block scope you can totally access them outside that scope... When defining variables with #let, we won’t have this weird out-of-scope access problem... Arrow functions give access to their defining environment while regular functions give access to their calling environment. This access is possible through the special this keyword... this keyword inside a regular function depends on how the function was called... The value of the this keyword inside an arrow function depends on where the function was defined... functions .call, .apply, and .bind can be used to change the calling environment

Все переменные внутри функции – это свойства специального внутреннего объекта LexicalEnvironment, который создаётся при её запуске... При создании функция получает скрытое свойство [[Scope]], которое ссылается на лексическое окружение, в котором она была создана... Иногда свойства, привязанные к функции, называют «статическими переменными»... Замыкание – это функция вместе со всеми внешними переменными, которые ей доступны.

hoisting — декларации всех используемых переменных переносятся в начало функции


var declarations have some odd scoping rules... var declarations are accessible anywhere within their containing function, module, namespace, or global scope - all which we’ll go over later on - regardless of the containing block. Some people call this var-scoping or function-scoping. Parameters are also function scoped... When a variable is declared using let, it uses what some call lexical-scoping or block-scoping. Unlike variables declared with var whose scopes leak out to their containing function, block-scoped variables are not visible outside of their nearest containing block or for-loop... Variables declared in a catch clause also have similar scoping rules. Another property of block-scoped variables is that they can’t be read or written to before they’re actually declared.

checking variable scope[edit]

Each global variable is stored as a property on the global object (window in a browser environment, global in NodeJS)... window.hasOwnProperty('myGlobalVar')


function declaration in a statement always starts with the keyword function. Otherwise it’s a function expression... function declaration in conditionals is allowed in non-strict mode... function name can be inferred. For example, when the anonymous is assigned to a variable... Shorthand method definition can be used in a method declaration on object literals and ES2015 classes... generator function in JavaScript returns a Generator object.. a star character *... function object type has a constructor: Function..The functions created this way don’t have access to the current scope, thus closures cannot be created.

Shorthand and dynamic properties[edit]

const obj = {
  p1: 10,        // Plain old object property (don't abbreviate)

  f1() {},       // Define a shorthand function property

  InverseOfPI,   // Define a shorthand regular property

  f2: () => {},  // Define an arrow function property

  [mystery]: 42, // Define a dynamic property


JavaScript will first evaluate the expression inside [] and whatever that expression evaluates to becomes the object’s new property. For the example above, the obj object will have a property answer with the value of 42.


This category has the following 4 subcategories, out of 4 total.



Pages in category "JS"

The following 10 pages are in this category, out of 10 total.