Many have pointed out that when you use typeof null
in Javascript, the result is object
:
console.log(typeof null);
.as-console {background-color:black !important; color:lime;}
.as-console-wrapper {max-height:100% !important; top:0;}
A summary table of possible return values for typeof
(sourced from MDN) is provided below:
Type | Result
Undefined | "undefined"
Null | "object" (see below)
Boolean | "boolean"
Number | "number"
String | "string"
Symbol (new in ECMAScript 2015) | "symbol"
Host object (provided by the JS environment) | Implementation-dependent
Function object (implements [[Call]] in ECMA-262 terms) | "function"
Any other object | "object"
Upon reviewing your code, it seems like a reorganization could enhance readability:
let lang = this.$store.state.lang
if (!lang)
lang = 'nl'
if (name && name[lang] && typeof name[lang] === 'string')
return name[lang];
return '';
The explicit check for default language assignment is redundant in your case since you've already set it to nl
if not defined:
return name['nl'] ? name['nl'] : ''