console.log(typeof null); console.log(typeof undefined); console.log(typeof 42); console.log(typeof 'hello');
In JavaScript, typeof null returns "object" due to legacy reasons. typeof undefined returns "undefined". Numbers and strings return "number" and "string" respectively.
console.log(Boolean(0)); console.log(Boolean('')); console.log(Boolean('false')); console.log(Boolean(null));
In JavaScript, 0, empty string '', and null are falsy values, so Boolean conversion returns false. The string 'false' is a non-empty string, so it is truthy and converts to true.
Symbols are unique and immutable primitive values. Each call to Symbol() creates a new unique symbol, so two symbols are never equal. Symbols can be used as unique keys for object properties. They cannot be automatically converted to strings; explicit conversion is needed.
console.log(typeof 9007199254740991n); console.log(typeof true); console.log(typeof '123'); console.log(typeof undefined);
The typeof operator returns "bigint" for BigInt values, "boolean" for booleans, "string" for strings, and "undefined" for undefined. null is not returned by typeof undefined.
const str = 'hello'; str[0] = 'H'; console.log(str);
Strings are immutable primitives in JavaScript. Trying to assign to an index like str[0] = 'H' does not change the string and does not throw an error. The original string remains unchanged, so console.log(str) outputs hello.