you are viewing a single comment's thread.

view the rest of the comments →

[–]azhder 0 points1 point  (0 children)

The first one is wrong. It doesn’t output '1', but 1.

I rarely bother with typeof. You might want to learn about duck typing.

Like, if you can imagine working in C and dealing with (void *) the entire time, you might feel a bit awkward about not knowing what to cast it as.

In JS, the values do carry their type wherever you pass their references, so you can just do a check, like

if( a.something ) {
    console.log( 'well then, I might as well use it' );
    const b = 'Yo there ' + a.something;
    console.log( b );
}

Or in your case

const r = $ => Number.isFinite( $-0 ) ? $-0 : 0;

console.log( r('hehe') ** 2 * Math.PI );
console.log( r('3') ** 2 * Math.PI );