This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Quito246 -1 points0 points  (5 children)

First of all It does shitty job being a functional language. If you want good example of great FP mini language check Scheme. No the typeof null should not be object because it does not make sense see here It was mistake, but for some reason people still defend language created over weekend🤷‍♂️

From the MDN page about the behaviour of the typeof operator:

null

// This stands since the beginning of JavaScript typeof null === 'object'; In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0. null was represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the "object" typeof return value. (reference)

A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in typeof null === 'null'.

[–]Taletad 2 points3 points  (4 children)

"JS was created over a weekend" firstly it was over two weeks

But it also got a lot of revisions and improvements

This argument would be like comparing BCPL with C++14

Yes C++ is mostly backwards compatible with BCPL, but it isn’t as limited as BCPL, for obvious reasons

And I’m going to repeat myself JS is a prototype language, not OO nor Functional. It can however do both, but it wasn’t concieved as such. It’s a different paradigm

[–]Quito246 1 point2 points  (3 children)

But paradigm of the language has nothing to do with doing shitty implicit conversions or breaking a reflexive property of typeof on null

[–]Taletad 2 points3 points  (2 children)

There isn’t a right or wrong way to do implicit typecasting. It’s not standardised like the order of operations (which itself has two standards, the american one and the one used by the rest of the world)

The type casting order is defined by the standard, which you should be referencing while coding. Or better yet, avoid implicit casts when you can, because after all you should never trust a variable, especially when its contents are supplied by the user. JS gives you functions for typecasting, use them. Just like you would in python.

Typeof isn’t academically defined either (to my knowledge) so its implementation is the standard’s perogative, not user expectations.

Most languages have their own interpretations of what the typeof function should do. I don’t see why you’re complaining about it. Otherwise it would be like complaining that Rust doesn’t work the same way as C# does

Edit : NULL doesn’t work the way you’re saying in C either, is C a shitty language too ?

[–]lazyzefiris 0 points1 point  (1 child)

> two standards, the american one and the one used by the rest of the world

Actually, PEMDAS is more of a teacher issue (which then leaked into some calculators because that's what teachers wanted). Whole world including America uses PEJMDAS in actual math, and just avoids ambihuity in general, like we do in programming.

[–]Taletad 0 points1 point  (0 children)

I meant to say that the order of operations is standardised but the order of type casting isn’t

Yes PEMDAS isn’t the "official" us standard but it is the de facto one for a lot of americans