let nothing: void = undefined;
console.log(nothing); // undefined
console.log(typeof nothing); // undefined
// console.log(nothing + 1); // error : Operator '+' cannot be applied to types 'void' and 'number'.ts(2365)
// let nothing2: void = null; // error
let nothing3: any = undefined;
console.log(nothing3 + 1); // NaN
console.log(void + 1); // undefined
console.log(void + "1"); // undefined
// console.log(null + 1); // error
console.log(null + "1"); // null1
// console.log(undefined + 1); // error
console.log(undefined + "1"); // undefined1
Can someone explain these? And void operator return "undefined" but the result of the examples is not very clear. Please do not mark my question as a duplicate of this: i dont ask difference between undefined and null. And these a, b : i dont ask void is or is not an alias for undefined and also contrary to the accepted answer in the question you can not set null to void variable.
- What are void, undefined and null type structures?
- What are the differences between them?
- The only return type in the function is "return;" what does it return?
funcFoo(fooStr: string) {
let obj: T;
if ( ) {
...
return;
}
else if (...) {
...
return undefined;
}
return obj;
}