ÔÚjsÖÐundefinedÊÇʲô
ÔÚ javascript ÖУ¬undefined ÊÇÒ»¸öÈ«¾Ö±äÁ¿£¬´ú±íδ¸³ÖµµÄ±äÁ¿»òÊôÐÔ¡£ËüÊÇÒ»¸öÔʼֵ£¬ÀàÐÍΪ undefined£¬Óë null ²î±ð£¬ºóÕßÊÇÒ»¸öÏÔʽ¸³ÖµµÄ¿ÕÖµ¡£undefined ¿ÉÓÃÓÚ¼ì²é±äÁ¿ÊÇ·ñ¸³Öµ¡¢³õʼ»¯±äÁ¿ºÍÓÃÓÚº¯Êý²ÎÊýĬÈÏÖµ¡£
JavaScript ÖÐµÄ undefined
ʲôÊÇ undefined£¿
ÔÚ JavaScript ÖУ¬undefined ÊÇÒ»¸öÈ«¾Ö±äÁ¿£¬´ú±íÒ»¸öδ¸³ÖµµÄ±äÁ¿»òÉÐδÉùÃ÷µÄÊôÐÔ¡£
undefined µÄÌصã
ËüÊÇÒ»¸öÔʼֵ£¨primitive value£©£¬ÀàÐÍΪ undefined¡£
Ëü²»¿É±»¸³Öµ¡£
ËüÓë null ²î±ð£¬null ÊÇÒ»¸öÏÔʽ¸³ÖµµÄ¿ÕÖµ£¬¶ø undefined ÊÇĬÈϸ³Öµ¡£
undefined µÄÓ÷¨
¼ì²é±äÁ¿ÊÇ·ñÒѸ³Öµ£ºÊ¹Óà typeof ²Ù×÷·ûÀ´¼ì²é±äÁ¿µÄÀàÐÍ£¬ÈôÊÇÀàÐÍΪ undefined£¬Ôò±äÁ¿Î´¸³Öµ¡£
³õʼ»¯±äÁ¿£º¿ÉÒÔ½«±äÁ¿³õʼ»¯Îª undefined£¬ÌåÏÖÉÐδ¸³Öµ¡£
ÓÃÓÚº¯Êý²ÎÊý£ºµ±º¯ÊýûÓÐת´ïÈκβÎÊýʱ£¬ËüµÄ²ÎÊýĬÈÏÖµÊÇ undefined¡£
undefined Óë null µÄÇø±ð
null ÊÇÒ»¸öÏÔʽ¸³ÖµµÄ¿ÕÖµ£¬ÌåÏÖ¸ÃÖµ²»±£´æ¡£
undefined ÊÇÒ»¸öδ¸³ÖµµÄ±äÁ¿£¬ÌåÏÖ±äÁ¿»¹Ã»ÓÐÖµ¡£
ÑÏ¿áÏàµÈ£¨===£©½ÏÁ¿Ê±£¬undefined Óë null ²»ÏàµÈ¡£
ʾÀý
// δ¸³ÖµµÄ±äÁ¿ let myVariable; // ¼ì²é±äÁ¿ÊÇ·ñÒѸ³Öµ if (typeof myVariable === "undefined") { // ±äÁ¿Î´¸³Öµ } // ³õʼ»¯±äÁ¿Îª undefined const myObject = { name: "John", age: undefined, }; // º¯Êý²ÎÊýĬÈÏֵΪ undefined function myFunction(name, age) { if (age === undefined) { // age ²ÎÊýδת´ï } }
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇÔÚjsÖÐundefinedÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡