Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Objective-BB

Name: Anonymous 2012-09-03 19:01

[[[[[b] i] o] u] @"ENTERPRISE"]

Name: Anonymous 2012-09-04 22:07

The Achilles Heel of JavaScript is its inconsistent behavior across implementations. It is virtually impossible to use it to do anything robust on the client side.

JavaScript is weakly typed, and the automatic coercions that it does can produce surprising results. "2" + "3" is "23" (+, when applied to two strings, performs concatenation); "2" * "3" is 6. (Multiplication not defined for strings; so the language tries converting them to numerals, succeeds, and multiplies those). This can be surprising.

Rather annoying gotcha in array constructor. new Array() produces empty array; new Array(2,3) produces array with 2 and 3 as its elements. new Array(5) does not produce array with 5 as its single element; instead, it returns a 5-element array!

Whereas most languages have one universal singular value (null/nil/Void/whatever); JavaScript has three - "false", "null" and "undefined". That leads to confusing and irregular semantics.

No integral types - the only numeric type supported is an IEEE754 double-precision float. For a scripting language, this limitation is probably less obnoxious than it would be elsewhere.

Language has LexicalScoping, but with an interesting twist. Unlike JavaScripts brethen C/C++/Java/C#/etc, where variables introduced in an anonymous block within a function are only valid within that block; in JavaScript such variables are valid for the entire function.

Every script is executed in a single global namespace that is accessible in browsers with the window object.

Automatic type conversion between strings and numbers, combined with '+' overloaded to mean concatenation and addition. This creates very counterintuitive effects if you accidentally convert a number to a string:

 var i = 1; 
 // some code
 i = i + ""; // oops!
 // some more code
 i + 1;  // evaluates to the String '11'
 i - 1;  // evaluates to the Number 0

The automatic type conversion of the + function also leads to the intuitive effect that += 1 is different then the ++ operator:

 var j = "1";
 j++; // j becomes 2
 
 var k = "1";
 k += 1; // k becomes "11"




'' == '0' //false
0 == '' //true
0 == '0' //true
false == 'false' //false
false == '0' //true
false == undefined //false
false == null //false
null == undefined //true
typeof NaN //number
NaN == NaN //false

var a = [123];
var b = 123;
a == b; //true
a[0] == b[0]; //false

var a = [0];
a == a;  //true
a == !a; //true

" \t\r\n" == 0 // true
Math.min() < Math.max(); // false
",,," == Array((null,'cool',false,NaN,4)); // true

new Array([],null,undefined,null) == ",,,"; // true

var foo = [0];
foo == foo  // true
foo == !foo // true

function toInt(number) {return number && + number | 0 || 0;}
toInt("1");  // 1
toInt("1.2");  // 1
toInt("-1.2");  // -1
toInt(1.2);  // 1
toInt(0);  // 0
toInt("0");  // 0
toInt(Number.NaN);  // 0
toInt(1/0);  // 0


[] + [] //
[] + {} // [object Object]
{} + [] // 0
{} + {} // NaN
"S" - 1 // NaN




$ js --version
JavaScript-C 1.7.0 2007-10-03
usage: js [-PswWxCi] [-b branchlimit] [-c stackchunksize] [-v version] [-f scriptfile] [-e script] [-S maxstacksize] [scriptfile] [scriptarg...]
$ js
js> 0 == ''
true
js> false == 'false'
false
js> false == '0'
true
js> false == undefined
false
js> " \t\r\n" == 0
true
js> Math.min() < Math.max()
false
js> ",,," == Array((null,'cool',false,NaN,4))
true
js> var foo = [0]
js> foo == foo
true
js> foo == !foo
true
js> function toInt(number) {return number && + number | 0 || 0;}
js> toInt("1")
1
js> toInt("1.2")
1
js> toInt("-1.2")
-1
js> toInt(1/0)
0
js>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List