From IT Skills
Jump to: navigation, search

Operators[edit | edit source]

'==' or '==='[edit | edit source]

http://es5.github.io/#x11.9.3

Крайне рекомендуется использовать только операторы строгого равенства

used in #indexOf

iif, .?[edit | edit source]

http://www.whydohow.com/is-there-a-javascript-undefined-property-handling-like-in-angular2-templates/

null-coalescing as logical ||

&&, ||[edit | edit source]

&& evaluates as long as the statement is true. If it is true, it returns the last value. If it is false, it returns the first value that evaluated to false. That may be 0, null, false etc. || returns the first value that evaluates to true.

Types casting[edit | edit source]

!!myString; // convert to bool

+myString; // convert to number

~~myNumber; // double NOT bitwise operator is faster substitute for Math.floor()

typeof[edit | edit source]

  • Array.isArray

Classes[edit | edit source]

В ES6 появляются «настоящие» классы

Strings[edit | edit source]

use Regex where possible

  • substring

String method substring or slice

  • last characters

/substring$/.test(str)

  • last n characters

slice.(0, -n) - allows you to make the second argument negative

Hashed lists and dictionaries[edit | edit source]

iteration may be done by for(let key in dict)

Remove property from object[edit | edit source]

delete myObject.regex

Loops[edit | edit source]

If you want to iterate over an object's keys, use for (var key in object). If you want to iterate over an array’s elements, however, use for(var i = 0; i < array.length; i += 1)

in TypeScript iteration over elements is for(let i of list) construction

Filter[edit | edit source]

  • Array.prototype.filter

good support

  • Array.prototype.find - returns the value of the first element in the array that satisfies the provided testing function

bad support: no IE, Safari 7.1

Methods[edit | edit source]

toFixed[edit | edit source]

toFixed() з javascript використовуємо лише для внутрішніх розрахунків, для презентаційних цілей (показати юзеру) її ніззя, бо вона не враховує регіональні налаштування формату чисел

DOM and browser[edit | edit source]

querySelector[edit | edit source]

good support including Safari 3.1+, or IE8+

getBoundingClientRect[edit | edit source]

good support

Page redirect[edit | edit source]

як правильно зробити редірект через window.location

  • GetAppRoot() - кастомна ЖС функція
  • window.location.search

asynchronous[edit | edit source]

async/await[edit | edit source]

bad support, no IE, no Windows 8.1, but polyfilled in core-js

Async functions from iOS versions#10.3

setTimeout и setInterval[edit | edit source]

Pages in category "JS coding guide"

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