The js constructor returns the value of the primitive type, gets the properties that do not exist, and the result is undefined without reporting an error

When the

constructor returns the value of the primitive type, it evaluates for attributes that do not exist, and the result is undefined without error

related codes

function F3() {
    this.name = "f3";
    return 5;
}

console.log(new F3()); // ,  {name: f3}
console.log(new F3().name); // f3
console.log(F3()); // 5 
console.log(F3().name); // 5.name >> undefined ????

run the following

console.log(5.name) //  Uncaught SyntaxError: Invalid or unexpected token
Mar.24,2022

basic types are returned before
basic types are returned when new, and the "this" ~ ~

is still returned from new.

if you do the following, you are making a function call

(this.name actually implicitly assigns a name to window when the function is called) remind ~

Direct numbers.
5. Can't tell whether it's a decimal point or a decimal point. Attribute
so (5). Name is to parse 5..name synonym 5.0.name synonym


dereferencing non-existent attributes of values (not null and undefined) will not report an error

.

the latter is a syntax error, not a run-time error, and (5) .name does not report an error

Menu