After research, there is a big difference between the two. I don’t know what the difference is between the two in English. The research results are as follows
Test os:ubuntu
Test browser: chrome
Test Case 1
console.log(a)
ReferenceError: a is not defined
Test Case 2
var a
console.log(a)
No errors were reported, but the output was undefined
Test Case 2
var b = {};
console.log(ba)
No errors were reported, but the output was undefined
Test Case 3
function c() {
}
var d = new c();
console.log(da)
No errors were reported, but undefined
About typeof
All the above objects used for testing are returned with typeof. String("undefined")
About or operation||
var d = a||3
Report an error a not defined
var a;
var d = a || 3
Result: d==3
var c = 22 || 44
c==22
var c = false || 33
c == 33
if(x) {
}
Report an error
var x
if(x) {
}
If not executed
Summarize:
There are two types of undefined in js, although the return is String("undefined")
After definition, but without any operation or an undefined property of an object, it belongs to undefined that can be used for operation and can be used as a logical operation.
The second type of variable is completely undefined and has no background (xa, although x has no a attribute, but gives x face), and cannot be used as an error type unless the typeof function is used.
The or operation in js does not return the bool value, but returns the value calculated by js on the last condition on both sides. For example, 1||2 1 is true, 2 does not need to be calculated, so 1||2 == 1 a|| 1 Report an error
var a; a|| 1 == 1;
I found this dictionary and translated it
undefined can be translated into: unclear, that is, I don't know what to do
And not defined can be translated into undefined