Javascript, The weird parts— Part 1

Define constructors with an arrow function

let f = function() {
this.number = 10;
};
new f(); // -> { 'number': 10 }
let f = () => {
this.number = 10;
};
new f(); // -> TypeError: f is not a constructor
1 < 2 < 3; // -> true
3 > 2 > 1; // -> false
1 < 2 < 3; // 1 < 2 -> true
true < 3; // true -> 1
1 < 3; // -> true
3 > 2 > 1; // 3 > 2 -> true
true > 1; // true -> 1
1 > 1; // -> false

Number.MIN_VALUE is the smallest number, which is greater than zero:

Number.MIN_VALUE > 0; // -> true

Strings aren’t instances of String

"abc"; // 'str'
typeof "abc"; // 'string'
"abc" instanceof String; // false

Object as a key of an object’s property

{ [{}]: {} } // -> { '[object Object]': {} }

Array.prototype.sort()

[ 10, 1, 5].sort() // -> [ 1, 10, 5]
[10, 1, 5].sort((a,b)=> a-b)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store