दोन्ही "कोणता मूल्य नाही" हे प्रतिनिधित्व करतात, परंतु भिन्न हेतू आणि उत्पत्तीसह।
दोन्ही "कोणता मूल्य नाही" हे प्रतिनिधित्व करतात, परंतु भिन्न हेतू आणि उत्पत्तीसह।
undefined: एक मूल्य का अभाव, सामान्यतः JavaScript इंजिनद्वारे सेट केला गेला — घोषित-परंतु-अनिर्धारित व्हेरिएबल, गहाळ ऑब्जेक्ट प्रॉपर्टी, फंक्शन पॅरामीटर ज्या तुम्ही पास केलेला नाही, किंवा return नाही असा फंक्शन।null: एक इच्छापूर्वक "रिक्त" मूल्य जो आप "येथे हेतूपूर्वक काहीच नाही" असे म्हणण्यासाठी सोपवता।let a; // undefined — declared, not assigned
const obj = {};
obj.missing; // undefined — property doesn't exist
function f() {}
f(); // undefined — no return
const b = null; // null — you chose to empty it
null == undefined; // true — loose equality treats them as equal
null === undefined; // false — different types
typeof undefined; // "undefined"
typeof null; // "object" (historical bug)
const value = input ?? "default"; // defaults on EITHER null or undefined
user?.address?.city; // optional chaining — undefined if any link is null/undefined
null वापरा एक मूल्य इच्छापूर्वक साफ करण्यासाठी (उदा. "निवडलेला वापरकर्ता नाही"), आणि undefined ला "अद्याप सेट केलेले नाही" असे माना। ऑपरेटर ?? (nullish coalescing) आणि ?. (optional chaining) दोन्ही एकाच वेळी हाताळतात, जेव्हा ते इतके व्यापकपणे वापरले जातात।
सविस्तर उत्तरांसह IT मुलाखत प्रश्नांचे ग्रंथालय — Junior पासून Senior पर्यंत.
देणगी द्या