-
-
Save b2whats/90b5e6615266242cd43931c0083aebe7 to your computer and use it in GitHub Desktop.
a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typeof NaN == 'number'; | |
42 == [[[[[[[42]]]]]]]; | |
'foo' > 'bar'; | |
NaN != NaN; | |
null >= 0 // true, т.к. null преобразуется к 0 | |
null > 0 // false т.к. null преобразуется к 0 | |
null == 0 // false | |
5 - '3' === 2 | |
5 + '3' === '53' | |
'5' - '3' === 2 | |
'5' + + '5' === '55' | |
'foo' + + 'bar' === 'fooNaN' | |
'5' + - '2' === '5-2' | |
'5' + - + - - + - - + + - + - + - + - - - '-2' === '52' | |
[] + [] === '' | |
[] + {} === '[object Object]' | |
{} + [] === 0 | |
{} + {} === NaN | |
function _if(truthy, then) { | |
[then, function () {}][+!truthy](); | |
} | |
function ifElse(truthy, then, _else) { | |
[then, _else][+!truthy](); | |
} | |
function and(a, b) { | |
return !!((!!a + !!b) >> 1); | |
} | |
function or(a, b) { | |
return !!(!!a + !!b); | |
} | |
function _for(from, cond, augment, fn) { | |
var i = from; | |
_if(cond(i), function step() { | |
fn(i); | |
i = augment(i); | |
_if(cond(i), step); | |
}); | |
} | |
function _while(cond, fn) { | |
_if(cond(), function () { | |
fn(); | |
_while(cond, fn); | |
}); | |
} | |
нестрогое равенство рассматривается с приведением к числу a == b | |
нестрогое равенство рассматривается с приведением к булевому типу в if (a == b) | |
преобразование к строке происходит при операциях в которых участвует строка и операции над строками 1 + '1' // 11 | |
но 1 - '1' // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment