douglascrockford / howjavascriptworks

Programs from the book _How JavaScript Works_
319 stars 53 forks source link

$NEO.text returns empty string #13

Closed diachedelic closed 4 years ago

diachedelic commented 4 years ago

Calling $NEO.text("hello") returns an empty string in Chrome v83.

This is because the undefined wunth and twoth arguments are each passed to big_float.number, which returns NaN (the underlying result of Number(undefined)). Hence "hello".slice(NaN, NaN) is returned, which is an empty string.

Without this fix, the following module exports "89".

def name: "terrence"
def age: 88

def have birthday: ƒ person (
    "happy birthday" ≈ person.name ≈ "! You are now " ≈ person.age + 1
)

export have birthday({ name, age })
douglascrockford commented 4 years ago

Thank you so much. I put the fix in big_float.number so that it can correct more cases.