If obj.valueof () does not have override,Number (obj), will it enter an endless loop?

look at the JS Redbook. The description of Number (obj) is:
call obj.valueOf (), first. If obj.valueOf () belongs to any basic type, then convert it according to the rules. If the result of obj.valueOf () is NaN, the obj.toString () method is called

at the same time, obj.valueof () has a description:
syntax: obj.valueOf () / / the obj here is any object, not just the Object
function: to convert the object obj to the value of the original type, this method usually needs to override (override).
Custom object, valueOf () returns the object itself without overriding the valueOf ().

if obj.valueof () is not override, then it returns itself.

doubt that: Number (objNotOverrideValueOf) will enter an endless cycle?

Mar.09,2021

will not be an endless loop, but will return NaN
object implicitly converted to Number is the following process
first step: call valueOf () , if the basic type is returned, follow the basic type conversion rules. Do not perform step 2
step 2: call valueOf () to return itself, then call toString , and the returned string is generally "[object XXXX]" . Then convert the basic rules of the string, that is, NaN
https://codeshelper.com/a/11.

Menu