[{"data":1,"prerenderedAt":3152},["ShallowReactive",2],{"page-\u002Fjs\u002F02-variables-and-data-types":3},{"id":4,"title":5,"body":6,"description":39,"extension":3146,"meta":3147,"navigation":138,"path":3148,"seo":3149,"stem":3150,"__hash__":3151},"content\u002Fjs\u002F02-variables-and-data-types.md","02 — Variables & Data Types",{"type":7,"value":8,"toc":3110},"minimark",[9,13,259,392,523,681,831,920,1068,1254,1458,1591,1739,1877,1984,2129,2225,2404,2549,2697,2941,3106],[10,11,5],"h1",{"id":12},"_02-variables-data-types",[14,15,17,31,125,198],"question-wrapper",{"language":16},"javascript",[18,19,21,22,26,27,30],"h3",{"id":20},"q1-what-is-the-key-scoping-difference-between-var-and-let","Q1. What is the key scoping difference between ",[23,24,25],"code",{},"var"," and ",[23,28,29],{},"let","?",[32,33,34],"code-wrapper",{"language":16},[35,36,40],"pre",{"className":37,"code":38,"language":16,"meta":39,"style":39},"language-javascript shiki shiki-themes github-light github-dark","if (true) {\n  var a = 1;\n  let b = 2;\n}\nconsole.log(a);\nconsole.log(b);\n","",[23,41,42,62,80,96,102,115],{"__ignoreMap":39},[43,44,47,51,55,59],"span",{"class":45,"line":46},"line",1,[43,48,50],{"class":49},"svdQ7","if",[43,52,54],{"class":53},"ssxIu"," (",[43,56,58],{"class":57},"snvgF","true",[43,60,61],{"class":53},") {\n",[43,63,65,68,71,74,77],{"class":45,"line":64},2,[43,66,67],{"class":49},"  var",[43,69,70],{"class":53}," a ",[43,72,73],{"class":49},"=",[43,75,76],{"class":57}," 1",[43,78,79],{"class":53},";\n",[43,81,83,86,89,91,94],{"class":45,"line":82},3,[43,84,85],{"class":49},"  let",[43,87,88],{"class":53}," b ",[43,90,73],{"class":49},[43,92,93],{"class":57}," 2",[43,95,79],{"class":53},[43,97,99],{"class":45,"line":98},4,[43,100,101],{"class":53},"}\n",[43,103,105,108,112],{"class":45,"line":104},5,[43,106,107],{"class":53},"console.",[43,109,111],{"class":110},"sIsaT","log",[43,113,114],{"class":53},"(a);\n",[43,116,118,120,122],{"class":45,"line":117},6,[43,119,107],{"class":53},[43,121,111],{"class":110},[43,123,124],{"class":53},"(b);\n",[126,127,130,155,179,187],"ul",{"className":128},[129],"contains-task-list",[131,132,135,140,141,26,144,147,148,151,152],"li",{"className":133},[134],"task-list-item",[136,137],"input",{"disabled":138,"type":139},true,"checkbox"," Both ",[23,142,143],{},"a",[23,145,146],{},"b"," are accessible outside the block; the code logs ",[23,149,150],{},"1"," then ",[23,153,154],{},"2",[131,156,158,160,161,163,164,166,167,169,170,172,173,175,176],{"className":157},[134],[136,159],{"disabled":138,"type":139}," ",[23,162,25],{}," is function\u002Fglobal-scoped so ",[23,165,143],{}," logs ",[23,168,150],{},"; ",[23,171,29],{}," is block-scoped so accessing ",[23,174,146],{}," throws a ",[23,177,178],{},"ReferenceError",[131,180,182,184,185],{"className":181},[134],[136,183],{"disabled":138,"type":139}," Neither is accessible outside the block; both throw ",[23,186,178],{},[131,188,190,160,192,194,195,197],{"className":189},[134],[136,191],{"disabled":138,"type":139},[23,193,29],{}," is function-scoped and ",[23,196,25],{}," is block-scoped, the reverse of the truth",[199,200,201,205,224],"details",{},[202,203,204],"summary",{},"Show Answer",[206,207,208,212,213,163,215,166,217,169,219,172,221,223],"p",{},[209,210,211],"strong",{},"Answer:"," B — ",[23,214,25],{},[23,216,143],{},[23,218,150],{},[23,220,29],{},[23,222,146],{}," throws",[206,225,226,160,229,231,232,235,236,238,239,241,242,244,245,248,249,251,252,254,255,258],{},[209,227,228],{},"Explanation:",[23,230,25],{}," ignores block boundaries (",[23,233,234],{},"{}",") and attaches to the nearest function or global scope, so ",[23,237,143],{}," leaks out of the ",[23,240,50],{}," block. ",[23,243,29],{}," (and ",[23,246,247],{},"const",") are genuinely block-scoped, so ",[23,250,146],{}," does not exist outside the ",[23,253,50],{}," block, and referencing it throws ",[23,256,257],{},"ReferenceError: b is not defined",". Option A wrongly assumes both leak. Option D swaps the actual rule.",[14,260,261,267,297,352],{"language":16},[18,262,264,265,30],{"id":263},"q2-what-is-variable-hoisting-as-it-applies-to-var","Q2. What is variable hoisting, as it applies to ",[23,266,25],{},[32,268,269],{"language":16},[35,270,272],{"className":37,"code":271,"language":16,"meta":39,"style":39},"console.log(x);\nvar x = 5;\n",[23,273,274,283],{"__ignoreMap":39},[43,275,276,278,280],{"class":45,"line":46},[43,277,107],{"class":53},[43,279,111],{"class":110},[43,281,282],{"class":53},"(x);\n",[43,284,285,287,290,292,295],{"class":45,"line":64},[43,286,25],{"class":49},[43,288,289],{"class":53}," x ",[43,291,73],{"class":49},[43,293,294],{"class":57}," 5",[43,296,79],{"class":53},[126,298,300,313,331,340],{"className":299},[129],[131,301,303,305,306,308,309,312],{"className":302},[134],[136,304],{"disabled":138,"type":139}," This throws a ",[23,307,178],{}," because ",[23,310,311],{},"x"," is used before declaration",[131,314,316,318,319,322,323,326,327,330],{"className":315},[134],[136,317],{"disabled":138,"type":139}," This logs ",[23,320,321],{},"undefined",", because the declaration ",[23,324,325],{},"var x"," is hoisted to the top of scope but the assignment ",[23,328,329],{},"= 5"," is not",[131,332,334,318,336,339],{"className":333},[134],[136,335],{"disabled":138,"type":139},[23,337,338],{},"5",", because JavaScript hoists both the declaration and the assignment",[131,341,343,345,346,308,349,351],{"className":342},[134],[136,344],{"disabled":138,"type":139}," This is a ",[23,347,348],{},"SyntaxError",[23,350,25],{}," cannot be declared after use",[199,353,354,356,364],{},[202,355,204],{},[206,357,358,360,361,363],{},[209,359,211],{}," B — Logs ",[23,362,321],{},"; the declaration is hoisted but the assignment stays in place",[206,365,366,368,369,371,372,374,375,378,379,382,383,385,386,388,389,391],{},[209,367,228],{}," During compilation, ",[23,370,325],{}," is conceptually moved to the top of its enclosing scope and initialized to ",[23,373,321],{},"; the ",[23,376,377],{},"x = 5"," assignment still executes at its original position. So by the time ",[23,380,381],{},"console.log(x)"," runs, ",[23,384,311],{}," exists but hasn't been assigned yet. Option A confuses this with ",[23,387,29],{},"\u002F",[23,390,247],{},"'s TDZ behavior. Option C is the common misconception that hoisting moves the whole statement, initializer included — it only moves the declaration.",[14,393,394,398,428,471],{"language":16},[18,395,397],{"id":396},"q3-what-is-the-temporal-dead-zone-tdz","Q3. What is the Temporal Dead Zone (TDZ)?",[32,399,400],{"language":16},[35,401,403],{"className":37,"code":402,"language":16,"meta":39,"style":39},"console.log(y);\nlet y = 10;\n",[23,404,405,414],{"__ignoreMap":39},[43,406,407,409,411],{"class":45,"line":46},[43,408,107],{"class":53},[43,410,111],{"class":110},[43,412,413],{"class":53},"(y);\n",[43,415,416,418,421,423,426],{"class":45,"line":64},[43,417,29],{"class":49},[43,419,420],{"class":53}," y ",[43,422,73],{"class":49},[43,424,425],{"class":57}," 10",[43,427,79],{"class":53},[126,429,431,443,459,465],{"className":430},[129],[131,432,434,436,437,439,440,442],{"className":433},[134],[136,435],{"disabled":138,"type":139}," The period during which a ",[23,438,25],{}," variable holds ",[23,441,321],{}," before assignment",[131,444,446,448,449,388,451,453,454,456,457],{"className":445},[134],[136,447],{"disabled":138,"type":139}," The span between entering a scope and a ",[23,450,29],{},[23,452,247],{}," variable's declaration line, during which accessing the variable throws a ",[23,455,178],{}," instead of returning ",[23,458,321],{},[131,460,462,464],{"className":461},[134],[136,463],{"disabled":138,"type":139}," A deprecated ES5 feature no longer relevant in modern JS",[131,466,468,470],{"className":467},[134],[136,469],{"disabled":138,"type":139}," The time it takes the garbage collector to free an unused variable",[199,472,473,475,487],{},[202,474,204],{},[206,476,477,479,480,388,482,484,485],{},[209,478,211],{}," B — The span before a ",[23,481,29],{},[23,483,247],{}," declaration executes, where accessing it throws instead of returning ",[23,486,321],{},[206,488,489,160,491,26,493,495,496,498,499,501,502,505,506,509,510,513,514,516,517,519,520,522],{},[209,490,228],{},[23,492,29],{},[23,494,247],{}," are hoisted too, but unlike ",[23,497,25],{}," they are not initialized to ",[23,500,321],{}," — they remain in an uninitialized \"temporal dead zone\" from the top of the block until their declaration executes. ",[209,503,504],{},"Debug:"," this is why ",[23,507,508],{},"console.log(y)"," here throws ",[23,511,512],{},"ReferenceError: Cannot access 'y' before initialization"," rather than silently logging ",[23,515,321],{}," like the ",[23,518,25],{}," case would. Option A describes ",[23,521,25],{},"'s actual (different) behavior. Option C and D are fabricated.",[14,524,525,529,607],{},[18,526,528],{"id":527},"q4-which-of-the-following-are-javascript-primitive-types-select-the-option-that-lists-only-primitives","Q4. Which of the following are JavaScript primitive types? (Select the option that lists ONLY primitives)",[126,530,532,550,572,589],{"className":531},[129],[131,533,535,160,537,540,541,540,544,540,547],{"className":534},[134],[136,536],{"disabled":138,"type":139},[23,538,539],{},"string",", ",[23,542,543],{},"number",[23,545,546],{},"Array",[23,548,549],{},"boolean",[131,551,553,160,555,540,557,540,559,540,561,540,563,540,566,540,569],{"className":552},[134],[136,554],{"disabled":138,"type":139},[23,556,539],{},[23,558,543],{},[23,560,549],{},[23,562,321],{},[23,564,565],{},"null",[23,567,568],{},"symbol",[23,570,571],{},"bigint",[131,573,575,160,577,540,580,540,583,540,586],{"className":574},[134],[136,576],{"disabled":138,"type":139},[23,578,579],{},"object",[23,581,582],{},"function",[23,584,585],{},"Date",[23,587,588],{},"Map",[131,590,592,160,594,540,596,540,599,602,603,606],{"className":591},[134],[136,593],{"disabled":138,"type":139},[23,595,539],{},[23,597,598],{},"Number",[23,600,601],{},"Boolean"," (the wrapper objects created via ",[23,604,605],{},"new",")",[199,608,609,611,629],{},[202,610,204],{},[206,612,613,212,615,540,617,540,619,540,621,540,623,540,625,540,627],{},[209,614,211],{},[23,616,539],{},[23,618,543],{},[23,620,549],{},[23,622,321],{},[23,624,565],{},[23,626,568],{},[23,628,571],{},[206,630,631,633,634,540,636,540,638,540,640,540,642,540,644,646,647,649,650,540,652,654,655,657,658,660,661,664,665,668,669,672,673,676,677,680],{},[209,632,228],{}," JavaScript has exactly seven primitive types: ",[23,635,539],{},[23,637,543],{},[23,639,549],{},[23,641,321],{},[23,643,565],{},[23,645,568],{}," (ES2015), and ",[23,648,571],{}," (ES2020). Everything else — arrays, plain objects, functions, ",[23,651,585],{},[23,653,588],{}," — is a reference type (",[23,656,579],{}," under the hood). Option A wrongly includes ",[23,659,546],{},", which is a reference type. Option D is a trap: ",[23,662,663],{},"new String(\"x\")"," creates a boxed ",[666,667,579],"em",{},", not a primitive string — ",[23,670,671],{},"typeof new String(\"x\")"," is ",[23,674,675],{},"\"object\"",", not ",[23,678,679],{},"\"string\"",".",[14,682,683,687,742,798],{"language":16},[18,684,686],{"id":685},"q5-how-are-primitives-and-reference-types-objectsarrays-different-when-assigned-to-a-new-variable","Q5. How are primitives and reference types (objects\u002Farrays) different when assigned to a new variable?",[32,688,689],{"language":16},[35,690,692],{"className":37,"code":691,"language":16,"meta":39,"style":39},"let a = { count: 1 };\nlet b = a;\nb.count = 99;\nconsole.log(a.count);\n",[23,693,694,710,721,733],{"__ignoreMap":39},[43,695,696,698,700,702,705,707],{"class":45,"line":46},[43,697,29],{"class":49},[43,699,70],{"class":53},[43,701,73],{"class":49},[43,703,704],{"class":53}," { count: ",[43,706,150],{"class":57},[43,708,709],{"class":53}," };\n",[43,711,712,714,716,718],{"class":45,"line":64},[43,713,29],{"class":49},[43,715,88],{"class":53},[43,717,73],{"class":49},[43,719,720],{"class":53}," a;\n",[43,722,723,726,728,731],{"class":45,"line":82},[43,724,725],{"class":53},"b.count ",[43,727,73],{"class":49},[43,729,730],{"class":57}," 99",[43,732,79],{"class":53},[43,734,735,737,739],{"class":45,"line":98},[43,736,107],{"class":53},[43,738,111],{"class":110},[43,740,741],{"class":53},"(a.count);\n",[126,743,745,758,775,789],{"className":744},[129],[131,746,748,160,750,752,753,755,756],{"className":747},[134],[136,749],{"disabled":138,"type":139},[23,751,150],{},", because ",[23,754,146],{}," is a fully independent copy of ",[23,757,143],{},[131,759,761,160,763,752,766,769,770,26,772,774],{"className":760},[134],[136,762],{"disabled":138,"type":139},[23,764,765],{},"99",[23,767,768],{},"b = a"," copies the reference, so ",[23,771,143],{},[23,773,146],{}," point to the same object in memory",[131,776,778,160,780,782,783,786,787],{"className":777},[134],[136,779],{"disabled":138,"type":139},[23,781,321],{},", because reassigning ",[23,784,785],{},"b.count"," breaks the link to ",[23,788,143],{},[131,790,792,305,794,797],{"className":791},[134],[136,793],{"disabled":138,"type":139},[23,795,796],{},"TypeError"," because objects are immutable by default",[199,799,800,802,809],{},[202,801,204],{},[206,803,804,212,806,808],{},[209,805,211],{},[23,807,765],{},", because objects are assigned\u002Fcopied by reference",[206,810,811,813,814,817,818,26,820,822,823,826,827,830],{},[209,812,228],{}," Reference types are stored as a pointer to a location in memory; ",[23,815,816],{},"let b = a"," copies that pointer, not the object's contents, so ",[23,819,143],{},[23,821,146],{}," alias the same object — mutating via one is visible through the other. This is different from primitives, where ",[23,824,825],{},"let x = 1; let y = x;"," gives ",[23,828,829],{},"y"," a fully independent copy of the value. Option A describes primitive copy semantics, mistakenly applied to an object. Option C and D are fabricated — nothing here breaks a link or throws.",[14,832,833,841,875],{},[18,834,836,837,840],{"id":835},"q6-what-does-typeof-null-evaluate-to","Q6. What does ",[23,838,839],{},"typeof null"," evaluate to?",[126,842,844,852,860,867],{"className":843},[129],[131,845,847,160,849],{"className":846},[134],[136,848],{"disabled":138,"type":139},[23,850,851],{},"\"null\"",[131,853,855,160,857],{"className":854},[134],[136,856],{"disabled":138,"type":139},[23,858,859],{},"\"undefined\"",[131,861,863,160,865],{"className":862},[134],[136,864],{"disabled":138,"type":139},[23,866,675],{},[131,868,870,160,872],{"className":869},[134],[136,871],{"disabled":138,"type":139},[23,873,874],{},"\"boolean\"",[199,876,877,879,886],{},[202,878,204],{},[206,880,881,883,884],{},[209,882,211],{}," C — ",[23,885,675],{},[206,887,888,160,890,892,893,896,897,900,901,903,904,672,907,910,911,913,914,916,917,919],{},[209,889,228],{},[209,891,504],{}," this is one of JavaScript's most famous quirks — ",[23,894,895],{},"typeof null === \"object\""," is a bug baked into the language since its first implementation (null was represented internally with the same tag as objects) and has been kept for backward compatibility ever since; it will never be fixed. It does ",[666,898,899],{},"not"," mean ",[23,902,565],{}," is actually an object — ",[23,905,906],{},"null === undefined",[23,908,909],{},"false",", and ",[23,912,565],{}," has no properties\u002Fmethods. Option A is the intuitive-but-wrong guess. Option B confuses ",[23,915,565],{}," with ",[23,918,321],{},", a related but distinct \"empty\" value.",[14,921,922,933,976,1017],{"language":16},[18,923,925,926,929,930,840],{"id":924},"q7-what-does-typeof-nan-evaluate-to-and-what-does-nan-nan-evaluate-to","Q7. What does ",[23,927,928],{},"typeof NaN"," evaluate to, and what does ",[23,931,932],{},"NaN === NaN",[32,934,935],{"language":16},[35,936,938],{"className":37,"code":937,"language":16,"meta":39,"style":39},"console.log(typeof NaN);\nconsole.log(NaN === NaN);\n",[23,939,940,958],{"__ignoreMap":39},[43,941,942,944,946,949,952,955],{"class":45,"line":46},[43,943,107],{"class":53},[43,945,111],{"class":110},[43,947,948],{"class":53},"(",[43,950,951],{"class":49},"typeof",[43,953,954],{"class":57}," NaN",[43,956,957],{"class":53},");\n",[43,959,960,962,964,966,969,972,974],{"class":45,"line":64},[43,961,107],{"class":53},[43,963,111],{"class":110},[43,965,948],{"class":53},[43,967,968],{"class":57},"NaN",[43,970,971],{"class":49}," ===",[43,973,954],{"class":57},[43,975,957],{"class":53},[126,977,979,989,999,1008],{"className":978},[129],[131,980,982,160,984,26,987],{"className":981},[134],[136,983],{"disabled":138,"type":139},[23,985,986],{},"\"NaN\"",[23,988,58],{},[131,990,992,160,994,26,997],{"className":991},[134],[136,993],{"disabled":138,"type":139},[23,995,996],{},"\"number\"",[23,998,909],{},[131,1000,1002,160,1004,26,1006],{"className":1001},[134],[136,1003],{"disabled":138,"type":139},[23,1005,859],{},[23,1007,909],{},[131,1009,1011,160,1013,26,1015],{"className":1010},[134],[136,1012],{"disabled":138,"type":139},[23,1014,996],{},[23,1016,58],{},[199,1018,1019,1021,1029],{},[202,1020,204],{},[206,1022,1023,212,1025,26,1027],{},[209,1024,211],{},[23,1026,996],{},[23,1028,909],{},[206,1030,1031,160,1033,1035,1036,1038,1039,160,1041,1043,1044,1047,1048,672,1050,1052,1053,1055,1056,1059,1060,1063,1064,1067],{},[209,1032,228],{},[23,1034,968],{}," (\"Not a Number\") is, paradoxically, of type ",[23,1037,996],{}," — it represents an invalid numeric result but is still part of the number type. ",[209,1040,504],{},[23,1042,968],{}," is the ",[666,1045,1046],{},"only"," value in JavaScript that is not equal to itself, by IEEE-754 floating-point spec design, so ",[23,1049,932],{},[23,1051,909],{},". To actually test for ",[23,1054,968],{},", use ",[23,1057,1058],{},"Number.isNaN(x)"," (not the legacy, coercing global ",[23,1061,1062],{},"isNaN(x)",") or ",[23,1065,1066],{},"Object.is(x, NaN)",". Options A, C, and D all misstate one or both facts.",[14,1069,1070,1074,1133,1180],{"language":16},[18,1071,1073],{"id":1072},"q8-which-of-these-correctly-demonstrates-implicit-type-coercion-in-a-comparison","Q8. Which of these correctly demonstrates implicit type coercion in a comparison?",[32,1075,1076],{"language":16},[35,1077,1079],{"className":37,"code":1078,"language":16,"meta":39,"style":39},"console.log(\"5\" == 5);\nconsole.log(\"5\" === 5);\nconsole.log([] == false);\n",[23,1080,1081,1100,1116],{"__ignoreMap":39},[43,1082,1083,1085,1087,1089,1093,1096,1098],{"class":45,"line":46},[43,1084,107],{"class":53},[43,1086,111],{"class":110},[43,1088,948],{"class":53},[43,1090,1092],{"class":1091},"sJ6F3","\"5\"",[43,1094,1095],{"class":49}," ==",[43,1097,294],{"class":57},[43,1099,957],{"class":53},[43,1101,1102,1104,1106,1108,1110,1112,1114],{"class":45,"line":64},[43,1103,107],{"class":53},[43,1105,111],{"class":110},[43,1107,948],{"class":53},[43,1109,1092],{"class":1091},[43,1111,971],{"class":49},[43,1113,294],{"class":57},[43,1115,957],{"class":53},[43,1117,1118,1120,1122,1125,1128,1131],{"class":45,"line":82},[43,1119,107],{"class":53},[43,1121,111],{"class":110},[43,1123,1124],{"class":53},"([] ",[43,1126,1127],{"class":49},"==",[43,1129,1130],{"class":57}," false",[43,1132,957],{"class":53},[126,1134,1136,1147,1158,1169],{"className":1135},[129],[131,1137,1139,160,1141,540,1143,540,1145],{"className":1138},[134],[136,1140],{"disabled":138,"type":139},[23,1142,909],{},[23,1144,909],{},[23,1146,909],{},[131,1148,1150,160,1152,540,1154,540,1156],{"className":1149},[134],[136,1151],{"disabled":138,"type":139},[23,1153,58],{},[23,1155,58],{},[23,1157,58],{},[131,1159,1161,160,1163,540,1165,540,1167],{"className":1160},[134],[136,1162],{"disabled":138,"type":139},[23,1164,58],{},[23,1166,909],{},[23,1168,58],{},[131,1170,1172,160,1174,540,1176,540,1178],{"className":1171},[134],[136,1173],{"disabled":138,"type":139},[23,1175,58],{},[23,1177,909],{},[23,1179,909],{},[199,1181,1182,1184,1194],{},[202,1183,204],{},[206,1185,1186,883,1188,540,1190,540,1192],{},[209,1187,211],{},[23,1189,58],{},[23,1191,909],{},[23,1193,58],{},[206,1195,1196,160,1198,1200,1201,1204,1205,1207,1208,1211,1212,1207,1214,1217,1218,1221,1222,1225,1226,1229,1230,26,1232,1234,1235,26,1238,1240,1241,1243,1244,1247,1248,1250,1251,1253],{},[209,1197,228],{},[23,1199,1127],{}," performs type coercion before comparing: ",[23,1202,1203],{},"\"5\" == 5"," coerces the string to a number, giving ",[23,1206,58],{},". ",[23,1209,1210],{},"==="," performs no coercion, so comparing a string to a number is always ",[23,1213,909],{},[23,1215,1216],{},"[] == false"," is a classic gotcha: ",[23,1219,1220],{},"[]"," is coerced to ",[23,1223,1224],{},"\"\""," (via ",[23,1227,1228],{},"ToPrimitive","), then ",[23,1231,1224],{},[23,1233,909],{}," are both coerced to numbers (",[23,1236,1237],{},"0",[23,1239,1237],{},"), so it's ",[23,1242,58],{}," — despite an array and a boolean seeming completely unrelated. ",[209,1245,1246],{},"Idiom:"," this exact unpredictability is why ",[23,1249,1210],{}," is recommended over ",[23,1252,1127],{}," in production code.",[14,1255,1256,1263,1331,1383],{"language":16},[18,1257,1259,1260,30],{"id":1258},"q9-what-is-the-result-of-adding-a-number-and-a-string-with","Q9. What is the result of adding a number and a string with ",[23,1261,1262],{},"+",[32,1264,1265],{"language":16},[35,1266,1268],{"className":37,"code":1267,"language":16,"meta":39,"style":39},"console.log(1 + \"2\");\nconsole.log(1 + 2 + \"3\");\nconsole.log(\"1\" + 2 + 3);\n",[23,1269,1270,1288,1309],{"__ignoreMap":39},[43,1271,1272,1274,1276,1278,1280,1283,1286],{"class":45,"line":46},[43,1273,107],{"class":53},[43,1275,111],{"class":110},[43,1277,948],{"class":53},[43,1279,150],{"class":57},[43,1281,1282],{"class":49}," +",[43,1284,1285],{"class":1091}," \"2\"",[43,1287,957],{"class":53},[43,1289,1290,1292,1294,1296,1298,1300,1302,1304,1307],{"class":45,"line":64},[43,1291,107],{"class":53},[43,1293,111],{"class":110},[43,1295,948],{"class":53},[43,1297,150],{"class":57},[43,1299,1282],{"class":49},[43,1301,93],{"class":57},[43,1303,1282],{"class":49},[43,1305,1306],{"class":1091}," \"3\"",[43,1308,957],{"class":53},[43,1310,1311,1313,1315,1317,1320,1322,1324,1326,1329],{"class":45,"line":82},[43,1312,107],{"class":53},[43,1314,111],{"class":110},[43,1316,948],{"class":53},[43,1318,1319],{"class":1091},"\"1\"",[43,1321,1282],{"class":49},[43,1323,93],{"class":57},[43,1325,1282],{"class":49},[43,1327,1328],{"class":57}," 3",[43,1330,957],{"class":53},[126,1332,1334,1348,1361,1372],{"className":1333},[129],[131,1335,1337,160,1339,540,1342,540,1345],{"className":1336},[134],[136,1338],{"disabled":138,"type":139},[23,1340,1341],{},"\"12\"",[23,1343,1344],{},"\"33\"",[23,1346,1347],{},"\"123\"",[131,1349,1351,160,1353,540,1356,540,1358],{"className":1350},[134],[136,1352],{"disabled":138,"type":139},[23,1354,1355],{},"3",[23,1357,1344],{},[23,1359,1360],{},"\"15\"",[131,1362,1364,160,1366,540,1368,540,1370],{"className":1363},[134],[136,1365],{"disabled":138,"type":139},[23,1367,1341],{},[23,1369,1344],{},[23,1371,1344],{},[131,1373,1375,160,1377,540,1379,540,1381],{"className":1374},[134],[136,1376],{"disabled":138,"type":139},[23,1378,968],{},[23,1380,968],{},[23,1382,1347],{},[199,1384,1385,1387,1398],{},[202,1386,204],{},[206,1388,1389,1391,1392,540,1394,540,1396],{},[209,1390,211],{}," A — ",[23,1393,1341],{},[23,1395,1344],{},[23,1397,1347],{},[206,1399,1400,160,1402,1404,1405,1408,1409,1221,1411,1413,1414,1207,1416,1419,1420,1423,1424,1426,1427,1430,1431,1207,1433,1419,1436,1430,1439,1441,1442,1430,1445,1447,1448,1450,1451,1454,1455,1457],{},[209,1401,228],{},[23,1403,1262],{}," evaluates left-to-right. ",[23,1406,1407],{},"1 + \"2\"",": number meets string, so ",[23,1410,150],{},[23,1412,1319],{}," and they concatenate to ",[23,1415,1341],{},[23,1417,1418],{},"1 + 2 + \"3\"",": ",[23,1421,1422],{},"1 + 2"," happens first (both numbers) giving ",[23,1425,1355],{},", then ",[23,1428,1429],{},"3 + \"3\""," concatenates to ",[23,1432,1344],{},[23,1434,1435],{},"\"1\" + 2 + 3",[23,1437,1438],{},"\"1\" + 2",[23,1440,1341],{}," first (left-to-right), then ",[23,1443,1444],{},"\"12\" + 3",[23,1446,1347],{}," — note it does ",[209,1449,899],{}," add ",[23,1452,1453],{},"2 + 3"," first, because ",[23,1456,1262],{}," has no special \"do the numbers first\" rule; it strictly evaluates left to right. This ordering trap is a frequent source of bugs when mixing types.",[14,1459,1460,1467,1503,1546],{"language":16},[18,1461,1463,1464,1466],{"id":1462},"q10-what-happens-when-you-access-a-property-on-undefined-versus-declaring-a-variable-with-no-initializer","Q10. What happens when you access a property on ",[23,1465,321],{},", versus declaring a variable with no initializer?",[32,1468,1469],{"language":16},[35,1470,1472],{"className":37,"code":1471,"language":16,"meta":39,"style":39},"let x;\nconsole.log(x);\nconsole.log(x.length);\n",[23,1473,1474,1481,1489],{"__ignoreMap":39},[43,1475,1476,1478],{"class":45,"line":46},[43,1477,29],{"class":49},[43,1479,1480],{"class":53}," x;\n",[43,1482,1483,1485,1487],{"class":45,"line":64},[43,1484,107],{"class":53},[43,1486,111],{"class":110},[43,1488,282],{"class":53},[43,1490,1491,1493,1495,1498,1501],{"class":45,"line":82},[43,1492,107],{"class":53},[43,1494,111],{"class":110},[43,1496,1497],{"class":53},"(x.",[43,1499,1500],{"class":57},"length",[43,1502,957],{"class":53},[126,1504,1506,1517,1528,1537],{"className":1505},[129],[131,1507,1509,1511,1512,1514,1515],{"className":1508},[134],[136,1510],{"disabled":138,"type":139}," Logs ",[23,1513,321],{},", then logs ",[23,1516,1237],{},[131,1518,1520,1511,1522,1524,1525],{"className":1519},[134],[136,1521],{"disabled":138,"type":139},[23,1523,321],{},", then throws ",[23,1526,1527],{},"TypeError: Cannot read properties of undefined (reading 'length')",[131,1529,1531,1511,1533,1524,1535],{"className":1530},[134],[136,1532],{"disabled":138,"type":139},[23,1534,565],{},[23,1536,178],{},[131,1538,1540,1542,1543,1545],{"className":1539},[134],[136,1541],{"disabled":138,"type":139}," Both lines throw, because ",[23,1544,311],{}," is never assigned",[199,1547,1548,1550,1559],{},[202,1549,204],{},[206,1551,1552,360,1554,1556,1557],{},[209,1553,211],{},[23,1555,321],{},", then throws a ",[23,1558,796],{},[206,1560,1561,1563,1564,388,1566,1568,1569,1571,1572,1574,1575,1578,1579,1207,1581,1583,1584,1587,1588,1590],{},[209,1562,228],{}," A ",[23,1565,29],{},[23,1567,25],{}," declared without an initializer is automatically set to ",[23,1570,321],{}," (not an error to read it, unlike TDZ). But ",[23,1573,321],{}," is a primitive with no properties, so attempting to read ",[23,1576,1577],{},".length"," off it throws ",[23,1580,796],{},[209,1582,504],{}," this exact error is one of the most common in production JS, typically from an object that was expected to exist (e.g., an API response field) but didn't. The fix is optional chaining (",[23,1585,1586],{},"x?.length",") or an existence check before access. Option A wrongly assumes property access on ",[23,1589,321],{}," is safe.",[14,1592,1593,1600,1647,1687],{"language":16},[18,1594,1596,1597,1599],{"id":1595},"q11-what-is-the-result-of-typeof-applied-to-a-function","Q11. What is the result of ",[23,1598,951],{}," applied to a function?",[32,1601,1602],{"language":16},[35,1603,1605],{"className":37,"code":1604,"language":16,"meta":39,"style":39},"function greet() {}\nconsole.log(typeof greet);\nconsole.log(greet instanceof Object);\n",[23,1606,1607,1617,1630],{"__ignoreMap":39},[43,1608,1609,1611,1614],{"class":45,"line":46},[43,1610,582],{"class":49},[43,1612,1613],{"class":110}," greet",[43,1615,1616],{"class":53},"() {}\n",[43,1618,1619,1621,1623,1625,1627],{"class":45,"line":64},[43,1620,107],{"class":53},[43,1622,111],{"class":110},[43,1624,948],{"class":53},[43,1626,951],{"class":49},[43,1628,1629],{"class":53}," greet);\n",[43,1631,1632,1634,1636,1639,1642,1645],{"class":45,"line":82},[43,1633,107],{"class":53},[43,1635,111],{"class":110},[43,1637,1638],{"class":53},"(greet ",[43,1640,1641],{"class":49},"instanceof",[43,1643,1644],{"class":110}," Object",[43,1646,957],{"class":53},[126,1648,1650,1659,1669,1678],{"className":1649},[129],[131,1651,1653,160,1655,26,1657],{"className":1652},[134],[136,1654],{"disabled":138,"type":139},[23,1656,675],{},[23,1658,58],{},[131,1660,1662,160,1664,26,1667],{"className":1661},[134],[136,1663],{"disabled":138,"type":139},[23,1665,1666],{},"\"function\"",[23,1668,58],{},[131,1670,1672,160,1674,26,1676],{"className":1671},[134],[136,1673],{"disabled":138,"type":139},[23,1675,1666],{},[23,1677,909],{},[131,1679,1681,160,1683,26,1685],{"className":1680},[134],[136,1682],{"disabled":138,"type":139},[23,1684,675],{},[23,1686,909],{},[199,1688,1689,1691,1699],{},[202,1690,204],{},[206,1692,1693,212,1695,26,1697],{},[209,1694,211],{},[23,1696,1666],{},[23,1698,58],{},[206,1700,1701,1703,1704,1706,1707,1709,1710,1712,1713,1716,1717,1719,1720,1722,1723,1725,1726,1728,1729,1731,1732,1735,1736,680],{},[209,1702,228],{}," JavaScript special-cases ",[23,1705,951],{}," for callable objects, returning ",[23,1708,1666],{}," even though functions are technically a subtype of ",[23,1711,579],{}," under the hood — which is why ",[23,1714,1715],{},"greet instanceof Object"," is also ",[23,1718,58],{},". This dual nature surprises people who expect ",[23,1721,951],{}," categories and the prototype chain to be mutually exclusive. Option A misses that ",[23,1724,951],{}," has a dedicated ",[23,1727,1666],{}," result. Options C and D get the ",[23,1730,1641],{}," half wrong — functions genuinely do inherit from ",[23,1733,1734],{},"Object.prototype"," via ",[23,1737,1738],{},"Function.prototype",[14,1740,1741,1749,1795,1839],{"language":16},[18,1742,1744,1745,1748],{"id":1743},"q12-what-does-01-02-03-evaluate-to-and-why","Q12. What does ",[23,1746,1747],{},"0.1 + 0.2 === 0.3"," evaluate to, and why?",[32,1750,1751],{"language":16},[35,1752,1754],{"className":37,"code":1753,"language":16,"meta":39,"style":39},"console.log(0.1 + 0.2 === 0.3);\nconsole.log(0.1 + 0.2);\n",[23,1755,1756,1779],{"__ignoreMap":39},[43,1757,1758,1760,1762,1764,1767,1769,1772,1774,1777],{"class":45,"line":46},[43,1759,107],{"class":53},[43,1761,111],{"class":110},[43,1763,948],{"class":53},[43,1765,1766],{"class":57},"0.1",[43,1768,1282],{"class":49},[43,1770,1771],{"class":57}," 0.2",[43,1773,971],{"class":49},[43,1775,1776],{"class":57}," 0.3",[43,1778,957],{"class":53},[43,1780,1781,1783,1785,1787,1789,1791,1793],{"class":45,"line":64},[43,1782,107],{"class":53},[43,1784,111],{"class":110},[43,1786,948],{"class":53},[43,1788,1766],{"class":57},[43,1790,1282],{"class":49},[43,1792,1771],{"class":57},[43,1794,957],{"class":53},[126,1796,1798,1806,1821,1829],{"className":1797},[129],[131,1799,1801,160,1803,1805],{"className":1800},[134],[136,1802],{"disabled":138,"type":139},[23,1804,58],{},"; JavaScript numbers are always exact",[131,1807,1809,160,1811,169,1813,1816,1817,1820],{"className":1808},[134],[136,1810],{"disabled":138,"type":139},[23,1812,909],{},[23,1814,1815],{},"0.1 + 0.2"," actually equals ",[23,1818,1819],{},"0.30000000000000004"," due to IEEE-754 double-precision floating-point representation, which cannot represent most decimal fractions exactly",[131,1822,1824,160,1826,1828],{"className":1823},[134],[136,1825],{"disabled":138,"type":139},[23,1827,909],{},"; this is a bug specific to V8 that other engines don't have",[131,1830,1832,160,1834,1836,1837],{"className":1831},[134],[136,1833],{"disabled":138,"type":139},[23,1835,58],{},"; JavaScript rounds floating point arithmetic automatically for ",[23,1838,1210],{},[199,1840,1841,1843,1853],{},[202,1842,204],{},[206,1844,1845,212,1847,1849,1850,1852],{},[209,1846,211],{},[23,1848,909],{},"; the sum is ",[23,1851,1819],{}," due to IEEE-754 binary floating-point representation",[206,1854,1855,160,1857,1860,1861,1863,1864,26,1866,1869,1870,1873,1874,1876],{},[209,1856,228],{},[209,1858,1859],{},"Portability:"," JavaScript's ",[23,1862,543],{}," type uses IEEE-754 double-precision floats (as do essentially all mainstream languages using this format — Python, Java, C, etc. exhibit the identical rounding, so this is not V8-specific). Fractions like ",[23,1865,1766],{},[23,1867,1868],{},"0.2"," cannot be represented exactly in binary floating point, so tiny representation errors accumulate. The correct way to compare is checking the difference is within an epsilon (e.g., ",[23,1871,1872],{},"Math.abs(a - b) \u003C Number.EPSILON","), not ",[23,1875,1210],{},". Option A and D are false — there is no automatic rounding. Option C is a plausible-sounding but wrong claim of engine-specific behavior.",[14,1878,1879,1886,1902,1948],{"language":16},[18,1880,1882,1883,1885],{"id":1881},"q13-what-is-the-type-and-value-of-an-empty-const-declaration-attempt","Q13. What is the type and value of an empty ",[23,1884,247],{}," declaration attempt?",[32,1887,1888],{"language":16},[35,1889,1891],{"className":37,"code":1890,"language":16,"meta":39,"style":39},"const PI;\n",[23,1892,1893],{"__ignoreMap":39},[43,1894,1895,1897,1900],{"class":45,"line":46},[43,1896,247],{"class":49},[43,1898,1899],{"class":57}," PI",[43,1901,79],{"class":53},[126,1903,1905,1917,1929,1939],{"className":1904},[129],[131,1906,1908,1910,1911,672,1914,1916],{"className":1907},[134],[136,1909],{"disabled":138,"type":139}," Valid; ",[23,1912,1913],{},"PI",[23,1915,321],{}," until assigned later",[131,1918,1920,160,1922,1925,1926,1928],{"className":1919},[134],[136,1921],{"disabled":138,"type":139},[23,1923,1924],{},"SyntaxError: Missing initializer in const declaration"," — ",[23,1927,247],{}," requires an initializer at declaration time",[131,1930,1932,1910,1934,1936,1937],{"className":1931},[134],[136,1933],{"disabled":138,"type":139},[23,1935,1913],{}," defaults to ",[23,1938,1237],{},[131,1940,1942,1944,1945,1947],{"className":1941},[134],[136,1943],{"disabled":138,"type":139}," Valid, but ",[23,1946,1913],{}," enters a permanent TDZ",[199,1949,1950,1952,1961],{},[202,1951,204],{},[206,1953,1954,212,1956,169,1958,1960],{},[209,1955,211],{},[23,1957,348],{},[23,1959,247],{}," requires an initializer",[206,1962,1963,1965,1966,26,1968,540,1970,1972,1973,1975,1976,1978,1979,916,1981,1983],{},[209,1964,228],{}," Unlike ",[23,1967,29],{},[23,1969,25],{},[23,1971,247],{}," bindings must be initialized in the same statement they're declared — there is no such thing as \"declare now, assign later\" for ",[23,1974,247],{},", because a ",[23,1977,247],{}," binding can never be reassigned at all. Option A confuses ",[23,1980,247],{},[23,1982,29],{},"'s allowed no-initializer form. Options C and D invent behavior that doesn't exist — this is a parse-time error, so the code never runs.",[14,1985,1986,1993,2044,2093],{"language":16},[18,1987,1989,1990,1992],{"id":1988},"q14-does-const-make-an-objects-contents-immutable","Q14. Does ",[23,1991,247],{}," make an object's contents immutable?",[32,1994,1995],{"language":16},[35,1996,1998],{"className":37,"code":1997,"language":16,"meta":39,"style":39},"const user = { name: \"Ana\" };\nuser.name = \"Beto\";\nuser = { name: \"Carla\" };\n",[23,1999,2000,2018,2030],{"__ignoreMap":39},[43,2001,2002,2004,2007,2010,2013,2016],{"class":45,"line":46},[43,2003,247],{"class":49},[43,2005,2006],{"class":57}," user",[43,2008,2009],{"class":49}," =",[43,2011,2012],{"class":53}," { name: ",[43,2014,2015],{"class":1091},"\"Ana\"",[43,2017,709],{"class":53},[43,2019,2020,2023,2025,2028],{"class":45,"line":64},[43,2021,2022],{"class":53},"user.name ",[43,2024,73],{"class":49},[43,2026,2027],{"class":1091}," \"Beto\"",[43,2029,79],{"class":53},[43,2031,2032,2035,2037,2039,2042],{"class":45,"line":82},[43,2033,2034],{"class":53},"user ",[43,2036,73],{"class":49},[43,2038,2012],{"class":53},[43,2040,2041],{"class":1091},"\"Carla\"",[43,2043,709],{"class":53},[126,2045,2047,2056,2073,2081],{"className":2046},[129],[131,2048,2050,2052,2053,2055],{"className":2049},[134],[136,2051],{"disabled":138,"type":139}," Both lines work fine — ",[23,2054,247],{}," prevents any mutation",[131,2057,2059,160,2061,2064,2065,2068,2069,2072],{"className":2058},[134],[136,2060],{"disabled":138,"type":139},[23,2062,2063],{},"user.name = \"Beto\""," works (mutating properties is allowed); ",[23,2066,2067],{},"user = {...}"," throws ",[23,2070,2071],{},"TypeError: Assignment to constant variable"," (reassigning the binding is not allowed)",[131,2074,2076,2078,2079],{"className":2075},[134],[136,2077],{"disabled":138,"type":139}," Both lines throw ",[23,2080,796],{},[131,2082,2084,160,2086,2088,2089,2092],{"className":2083},[134],[136,2085],{"disabled":138,"type":139},[23,2087,2063],{}," throws, but reassigning ",[23,2090,2091],{},"user"," works",[199,2094,2095,2097,2102],{},[202,2096,204],{},[206,2098,2099,2101],{},[209,2100,211],{}," B — Mutating a property works; reassigning the binding throws",[206,2103,2104,160,2106,2108,2109,2112,2113,2115,2116,2118,2119,2122,2123,2125,2126,2128],{},[209,2105,228],{},[23,2107,247],{}," only freezes the ",[666,2110,2111],{},"binding"," (the variable name cannot be pointed at a new value) — it says nothing about the mutability of the value itself. Since ",[23,2114,2091],{}," still refers to the same object, mutating its properties is completely legal. ",[209,2117,1246],{}," to actually prevent mutation of the object's own properties, use ",[23,2120,2121],{},"Object.freeze(user)"," (shallow) in addition to ",[23,2124,247],{},". Option A is the classic misconception that ",[23,2127,247],{}," means \"constant\u002Fimmutable data.\" Option D reverses the true behavior.",[14,2130,2131,2135,2182],{},[18,2132,2134],{"id":2133},"q15-which-is-the-idiomatic-default-choice-for-variable-declarations-in-modern-javascript-and-why","Q15. Which is the idiomatic default choice for variable declarations in modern JavaScript, and why?",[126,2136,2138,2147,2165,2176],{"className":2137},[129],[131,2139,2141,2143,2144,2146],{"className":2140},[134],[136,2142],{"disabled":138,"type":139}," Always use ",[23,2145,25],{},", since it has the widest historical browser support",[131,2148,2150,2152,2153,2155,2156,2158,2159,2161,2162,2164],{"className":2149},[134],[136,2151],{"disabled":138,"type":139}," Default to ",[23,2154,247],{}," for bindings that are never reassigned, use ",[23,2157,29],{}," only when reassignment is genuinely needed, and avoid ",[23,2160,25],{}," — this communicates intent and avoids ",[23,2163,25],{},"'s function-scoping\u002Fhoisting pitfalls",[131,2166,2168,2143,2170,2172,2173,2175],{"className":2167},[134],[136,2169],{"disabled":138,"type":139},[23,2171,29],{}," everywhere for consistency, and reserve ",[23,2174,247],{}," only for primitive values",[131,2177,2179,2181],{"className":2178},[134],[136,2180],{"disabled":138,"type":139}," It doesn't matter; all three are functionally interchangeable in modern engines",[199,2183,2184,2186,2198],{},[202,2185,204],{},[206,2187,2188,2190,2191,1055,2193,2195,2196],{},[209,2189,211],{}," B — Default to ",[23,2192,247],{},[23,2194,29],{}," only when reassignment is needed, avoid ",[23,2197,25],{},[206,2199,2200,160,2202,2204,2205,2207,2208,2210,2211,2213,2214,2216,2217,388,2219,2221,2222,2224],{},[209,2201,228],{},[209,2203,1246],{}," preferring ",[23,2206,247],{}," signals to readers (and tooling\u002Flinters) that a binding won't be reassigned, catching accidental reassignment bugs at parse\u002Flint time; ",[23,2209,29],{},"'s block scoping avoids the classic ",[23,2212,25],{}," closure-in-loop bug (see Control Flow topic); ",[23,2215,25],{},"'s hoisting and function-scoping are considered legacy footguns in modern style guides (Airbnb, StandardJS, etc.) with no upside over ",[23,2218,29],{},[23,2220,247],{},". Option A is outdated advice from an era before ES2015 adoption. Option C undersells ",[23,2223,247],{},"'s usefulness for objects\u002Farrays too (the binding, not contents, is what's fixed). Option D ignores real, observable scoping differences.",[14,2226,2227,2233,2273,2339],{"language":16},[18,2228,2230,2231,30],{"id":2229},"q16-what-is-the-best-practice-way-to-check-if-a-value-is-nan","Q16. What is the best-practice way to check if a value is ",[23,2232,968],{},[32,2234,2235],{"language":16},[35,2236,2238],{"className":37,"code":2237,"language":16,"meta":39,"style":39},"function isInvalidNumber(val) {\n  return val !== val;\n}\n",[23,2239,2240,2255,2269],{"__ignoreMap":39},[43,2241,2242,2244,2247,2249,2253],{"class":45,"line":46},[43,2243,582],{"class":49},[43,2245,2246],{"class":110}," isInvalidNumber",[43,2248,948],{"class":53},[43,2250,2252],{"class":2251},"sCrzJ","val",[43,2254,61],{"class":53},[43,2256,2257,2260,2263,2266],{"class":45,"line":64},[43,2258,2259],{"class":49},"  return",[43,2261,2262],{"class":53}," val ",[43,2264,2265],{"class":49},"!==",[43,2267,2268],{"class":53}," val;\n",[43,2270,2271],{"class":45,"line":82},[43,2272,101],{"class":53},[126,2274,2276,2286,2317,2329],{"className":2275},[129],[131,2277,2279,2281,2282,2285],{"className":2278},[134],[136,2280],{"disabled":138,"type":139}," Use the global ",[23,2283,2284],{},"isNaN(val)"," function, since it's the shortest and most common option",[131,2287,2289,2291,2292,2295,2296,2299,2300,2303,2304,2306,2307,2310,2311,2313,2314,2316],{"className":2288},[134],[136,2290],{"disabled":138,"type":139}," Use ",[23,2293,2294],{},"Number.isNaN(val)",", because the global ",[23,2297,2298],{},"isNaN()"," first coerces its argument, causing false positives like ",[23,2301,2302],{},"isNaN(\"hello\")"," being ",[23,2305,58],{}," when the value isn't even numeric; ",[23,2308,2309],{},"Number.isNaN"," only returns ",[23,2312,58],{}," for the actual ",[23,2315,968],{}," value with no coercion",[131,2318,2320,2291,2322,2325,2326,2328],{"className":2319},[134],[136,2321],{"disabled":138,"type":139},[23,2323,2324],{},"val === NaN",", since ",[23,2327,968],{}," is a well-defined constant",[131,2330,2332,2334,2335,2338],{"className":2331},[134],[136,2333],{"disabled":138,"type":139}," The ",[23,2336,2337],{},"val !== val"," trick shown above is the only reliable method; all built-ins are broken",[199,2340,2341,2343,2351],{},[202,2342,204],{},[206,2344,2345,2347,2348,2350],{},[209,2346,211],{}," B — Use ",[23,2349,2294],{}," to avoid the global function's coercion-related false positives",[206,2352,2353,160,2355,2357,2358,2360,2361,672,2363,2365,2366,672,2369,2371,2372,2375,2376,2379,2380,2382,2383,160,2386,2388,2389,2391,2392,2394,2395,2397,2398,2400,2401,2403],{},[209,2354,228],{},[209,2356,1246],{}," the legacy global ",[23,2359,2298],{}," coerces its argument to a number first, so ",[23,2362,2302],{},[23,2364,58],{}," (because ",[23,2367,2368],{},"Number(\"hello\")",[23,2370,968],{},") even though ",[23,2373,2374],{},"\"hello\""," was never intended as a numeric check target — a classic false positive. ",[23,2377,2378],{},"Number.isNaN()"," (ES2015+) does no coercion, returning ",[23,2381,58],{}," only if the value literally ",[666,2384,2385],{},"is",[23,2387,968],{},". Option C is invalid — as established, ",[23,2390,932],{}," is always ",[23,2393,909],{},", so this check can never succeed. Option D is an overstatement — the ",[23,2396,2337],{}," trick does work (it exploits the same self-inequality), but ",[23,2399,2309],{}," is the clearer, idiomatic choice; it's not the ",[666,2402,1046],{}," reliable method.",[14,2405,2406,2413,2453,2501],{"language":16},[18,2407,2409,2410,30],{"id":2408},"q17-what-is-the-idiomatic-way-to-handle-very-large-integers-that-exceed-numbermax_safe_integer","Q17. What is the idiomatic way to handle very large integers that exceed ",[23,2411,2412],{},"Number.MAX_SAFE_INTEGER",[32,2414,2415],{"language":16},[35,2416,2418],{"className":37,"code":2417,"language":16,"meta":39,"style":39},"console.log(Number.MAX_SAFE_INTEGER);\nconsole.log(Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2);\n",[23,2419,2420,2429],{"__ignoreMap":39},[43,2421,2422,2424,2426],{"class":45,"line":46},[43,2423,107],{"class":53},[43,2425,111],{"class":110},[43,2427,2428],{"class":53},"(Number.MAX_SAFE_INTEGER);\n",[43,2430,2431,2433,2435,2438,2440,2442,2444,2447,2449,2451],{"class":45,"line":64},[43,2432,107],{"class":53},[43,2434,111],{"class":110},[43,2436,2437],{"class":53},"(Number.MAX_SAFE_INTEGER ",[43,2439,1262],{"class":49},[43,2441,76],{"class":57},[43,2443,971],{"class":49},[43,2445,2446],{"class":53}," Number.MAX_SAFE_INTEGER ",[43,2448,1262],{"class":49},[43,2450,93],{"class":57},[43,2452,957],{"class":53},[126,2454,2456,2462,2481,2491],{"className":2455},[129],[131,2457,2459,2461],{"className":2458},[134],[136,2460],{"disabled":138,"type":139}," Continue using regular numbers; JavaScript numbers have unlimited precision",[131,2463,2465,2467,2468,2470,2471,2474,2475,2477,2478],{"className":2464},[134],[136,2466],{"disabled":138,"type":139}," Use the ",[23,2469,571],{}," primitive type (e.g., ",[23,2472,2473],{},"9007199254740993n","), which represents arbitrary-precision integers exactly, instead of the ",[23,2476,543],{}," type, which silently loses precision beyond ",[23,2479,2480],{},"2^53 - 1",[131,2482,2484,2486,2487,2490],{"className":2483},[134],[136,2485],{"disabled":138,"type":139}," Round the result using ",[23,2488,2489],{},"Math.round()"," to fix precision loss",[131,2492,2494,2496,2497,2500],{"className":2493},[134],[136,2495],{"disabled":138,"type":139}," Store the number as a string and use ",[23,2498,2499],{},"parseInt()"," whenever arithmetic is needed",[199,2502,2503,2505,2514],{},[202,2504,204],{},[206,2506,2507,2347,2509,2511,2512],{},[209,2508,211],{},[23,2510,571],{}," for exact arbitrary-precision integers beyond ",[23,2513,2412],{},[206,2515,2516,160,2518,2521,2522,2524,2525,54,2527,2529,2530,2532,2533,2535,2536,2539,2540,2542,2543,2068,2546,2548],{},[209,2517,228],{},[209,2519,2520],{},"Safety:"," regular ",[23,2523,543],{}," values are IEEE-754 doubles that can only represent integers exactly up to ",[23,2526,2480],{},[23,2528,2412],{},"); beyond that, distinct integers can silently collapse to the same floating-point value (as the ",[23,2531,58],{}," result of the comparison above demonstrates) — a silent correctness bug, not an error you'd notice. ",[23,2534,571],{}," (suffix ",[23,2537,2538],{},"n",", ES2020) stores arbitrary-precision integers with no such ceiling, at the cost of not being directly mixable with ",[23,2541,543],{}," in arithmetic (",[23,2544,2545],{},"1n + 1",[23,2547,796],{},"). Option A is false — this is precisely the bug being demonstrated. Option C doesn't address the root precision-loss cause. Option D works but is a clunky workaround compared to a proper primitive type.",[14,2550,2551,2558,2606,2641],{"language":16},[18,2552,2554,2555,30],{"id":2553},"q18-which-best-describes-idiomatic-use-of-symbol","Q18. Which best describes idiomatic use of ",[23,2556,2557],{},"Symbol",[32,2559,2560],{"language":16},[35,2561,2563],{"className":37,"code":2562,"language":16,"meta":39,"style":39},"const id = Symbol(\"userId\");\nconst obj = { [id]: 42, name: \"Ana\" };\n",[23,2564,2565,2584],{"__ignoreMap":39},[43,2566,2567,2569,2572,2574,2577,2579,2582],{"class":45,"line":46},[43,2568,247],{"class":49},[43,2570,2571],{"class":57}," id",[43,2573,2009],{"class":49},[43,2575,2576],{"class":110}," Symbol",[43,2578,948],{"class":53},[43,2580,2581],{"class":1091},"\"userId\"",[43,2583,957],{"class":53},[43,2585,2586,2588,2591,2593,2596,2599,2602,2604],{"class":45,"line":64},[43,2587,247],{"class":49},[43,2589,2590],{"class":57}," obj",[43,2592,2009],{"class":49},[43,2594,2595],{"class":53}," { [id]: ",[43,2597,2598],{"class":57},"42",[43,2600,2601],{"class":53},", name: ",[43,2603,2015],{"class":1091},[43,2605,709],{"class":53},[126,2607,2609,2615,2621,2632],{"className":2608},[129],[131,2610,2612,2614],{"className":2611},[134],[136,2613],{"disabled":138,"type":139}," Symbols are mainly used to create guaranteed-unique property keys (e.g., to avoid accidental collisions with string keys or to define \"hidden,\" non-enumerable-by-default-iteration metadata), not as a general-purpose string replacement",[131,2616,2618,2620],{"className":2617},[134],[136,2619],{"disabled":138,"type":139}," Symbols are just a stylistic alternative to strings for any object key, interchangeable with strings in all cases",[131,2622,2624,160,2626,672,2629,2631],{"className":2623},[134],[136,2625],{"disabled":138,"type":139},[23,2627,2628],{},"Symbol(\"userId\") === Symbol(\"userId\")",[23,2630,58],{},", so symbols are good for deduplication",[131,2633,2635,2637,2638,2640],{"className":2634},[134],[136,2636],{"disabled":138,"type":139}," Symbols can be implicitly converted to strings via ",[23,2639,1262],{},", making them convenient for string concatenation",[199,2642,2643,2645,2650],{},[202,2644,204],{},[206,2646,2647,2649],{},[209,2648,211],{}," A — Symbols create guaranteed-unique keys, not a general string replacement",[206,2651,2652,2654,2655,2658,2659,2661,2662,2664,2665,540,2668,2671,2672,2675,2676,2678,2679,2681,2682,26,2685,2688,2689,2692,2693,2696],{},[209,2653,228],{}," Every ",[23,2656,2657],{},"Symbol()"," call produces a value unique from every other symbol, even with the same description string — so ",[23,2660,2628],{}," is actually ",[23,2663,909],{}," (making option C the tempting-but-wrong trap). Symbol-keyed properties don't show up in ",[23,2666,2667],{},"for...in",[23,2669,2670],{},"Object.keys()",", or ",[23,2673,2674],{},"JSON.stringify()"," by default, making them useful for \"semi-private\" metadata that won't collide with user-defined string keys. Option B ignores this uniqueness\u002Finterop purpose. Option D is false — ",[23,2677,2557],{}," values throw ",[23,2680,796],{}," when used with implicit string coercion (e.g., ",[23,2683,2684],{},"`${sym}`",[23,2686,2687],{},"sym + \"\""," both throw); you must call ",[23,2690,2691],{},".toString()"," or ",[23,2694,2695],{},".description"," explicitly.",[14,2698,2699,2703,2792,2859],{"language":16},[18,2700,2702],{"id":2701},"q19-why-does-this-equality-check-behave-unexpectedly-and-whats-the-idiomatic-fix","Q19. Why does this equality check behave unexpectedly, and what's the idiomatic fix?",[32,2704,2705],{"language":16},[35,2706,2708],{"className":37,"code":2707,"language":16,"meta":39,"style":39},"function isEmpty(value) {\n  return value == null;\n}\nconsole.log(isEmpty(undefined));\nconsole.log(isEmpty(null));\nconsole.log(isEmpty(0));\n",[23,2709,2710,2724,2738,2742,2760,2776],{"__ignoreMap":39},[43,2711,2712,2714,2717,2719,2722],{"class":45,"line":46},[43,2713,582],{"class":49},[43,2715,2716],{"class":110}," isEmpty",[43,2718,948],{"class":53},[43,2720,2721],{"class":2251},"value",[43,2723,61],{"class":53},[43,2725,2726,2728,2731,2733,2736],{"class":45,"line":64},[43,2727,2259],{"class":49},[43,2729,2730],{"class":53}," value ",[43,2732,1127],{"class":49},[43,2734,2735],{"class":57}," null",[43,2737,79],{"class":53},[43,2739,2740],{"class":45,"line":82},[43,2741,101],{"class":53},[43,2743,2744,2746,2748,2750,2753,2755,2757],{"class":45,"line":98},[43,2745,107],{"class":53},[43,2747,111],{"class":110},[43,2749,948],{"class":53},[43,2751,2752],{"class":110},"isEmpty",[43,2754,948],{"class":53},[43,2756,321],{"class":57},[43,2758,2759],{"class":53},"));\n",[43,2761,2762,2764,2766,2768,2770,2772,2774],{"class":45,"line":104},[43,2763,107],{"class":53},[43,2765,111],{"class":110},[43,2767,948],{"class":53},[43,2769,2752],{"class":110},[43,2771,948],{"class":53},[43,2773,565],{"class":57},[43,2775,2759],{"class":53},[43,2777,2778,2780,2782,2784,2786,2788,2790],{"class":45,"line":117},[43,2779,107],{"class":53},[43,2781,111],{"class":110},[43,2783,948],{"class":53},[43,2785,2752],{"class":110},[43,2787,948],{"class":53},[43,2789,1237],{"class":57},[43,2791,2759],{"class":53},[126,2793,2795,2808,2833,2845],{"className":2794},[129],[131,2796,2798,160,2800,2803,2804,2807],{"className":2797},[134],[136,2799],{"disabled":138,"type":139},[23,2801,2802],{},"value == null"," is a bug; it should always be written as ",[23,2805,2806],{},"value === null"," for safety",[131,2809,2811,160,2813,2816,2817,672,2820,2822,2823,2825,2826,26,2828,2830,2831],{"className":2810},[134],[136,2812],{"disabled":138,"type":139},[23,2814,2815],{},"== null"," is actually an idiomatic, intentional pattern: due to type coercion rules, ",[23,2818,2819],{},"null == undefined",[23,2821,58],{}," (and only to each other), so ",[23,2824,2802],{}," cleanly catches both ",[23,2827,565],{},[23,2829,321],{}," in one check without matching falsy-but-defined values like ",[23,2832,1237],{},[131,2834,2836,305,2838,308,2840,2842,2843],{"className":2835},[134],[136,2837],{"disabled":138,"type":139},[23,2839,796],{},[23,2841,565],{}," cannot be compared with ",[23,2844,1127],{},[131,2846,2848,160,2850,2853,2854,308,2856,2858],{"className":2847},[134],[136,2849],{"disabled":138,"type":139},[23,2851,2852],{},"isEmpty(0)"," returns ",[23,2855,58],{},[23,2857,1237],{}," is falsy",[199,2860,2861,2863,2875],{},[202,2862,204],{},[206,2864,2865,212,2867,2869,2870,26,2872,2874],{},[209,2866,211],{},[23,2868,2815],{}," intentionally catches both ",[23,2871,565],{},[23,2873,321],{}," via a special-cased coercion rule, without matching other falsy values",[206,2876,2877,160,2879,2881,2882,2884,2885,672,2887,2889,2890,26,2892,2894,2895,2897,2898,676,2900,676,2902,2904,2905,2907,2908,388,2911,2914,2915,2918,2919,540,2921,2918,2924,540,2926,2918,2928,2930,2931,2933,2934,2936,2937,2940],{},[209,2878,228],{},[209,2880,1246],{}," per the spec, ",[23,2883,1127],{}," has a special rule that ",[23,2886,2819],{},[23,2888,58],{},", but ",[23,2891,565],{},[23,2893,321],{}," are ",[23,2896,1127],{}," to nothing else (not ",[23,2899,1237],{},[23,2901,1224],{},[23,2903,909],{},"). This makes ",[23,2906,2802],{}," a widely-used, deliberate idiom to check for \"nullish\" in one line, predating ",[23,2909,2910],{},"??",[23,2912,2913],{},"?.",". So ",[23,2916,2917],{},"isEmpty(undefined)"," → ",[23,2920,58],{},[23,2922,2923],{},"isEmpty(null)",[23,2925,58],{},[23,2927,2852],{},[23,2929,909],{}," (0 is not loosely equal to null). Option A is overly cautious — this is one of the few places ",[23,2932,1127],{}," is considered acceptable\u002Fidiomatic rather than a footgun. Option D wrongly assumes truthiness is involved; this comparison uses the ",[23,2935,1127],{}," coercion table, not ",[23,2938,2939],{},"Boolean()"," coercion.",[14,2942,2943,2950,3001,3053],{"language":16},[18,2944,2946,2947,2949],{"id":2945},"q20-what-is-the-best-practice-explanation-for-why-typeof-is-safe-to-use-on-a-variable-that-might-not-be-declared-at-all-but-not-on-one-known-to-be-in-the-tdz","Q20. What is the best-practice explanation for why ",[23,2948,951],{}," is safe to use on a variable that might not be declared at all, but not on one known to be in the TDZ?",[32,2951,2952],{"language":16},[35,2953,2955],{"className":37,"code":2954,"language":16,"meta":39,"style":39},"console.log(typeof undeclaredVar);\n\nconsole.log(typeof laterVar);\nlet laterVar = 5;\n",[23,2956,2957,2970,2975,2988],{"__ignoreMap":39},[43,2958,2959,2961,2963,2965,2967],{"class":45,"line":46},[43,2960,107],{"class":53},[43,2962,111],{"class":110},[43,2964,948],{"class":53},[43,2966,951],{"class":49},[43,2968,2969],{"class":53}," undeclaredVar);\n",[43,2971,2972],{"class":45,"line":64},[43,2973,2974],{"emptyLinePlaceholder":138},"\n",[43,2976,2977,2979,2981,2983,2985],{"class":45,"line":82},[43,2978,107],{"class":53},[43,2980,111],{"class":110},[43,2982,948],{"class":53},[43,2984,951],{"class":49},[43,2986,2987],{"class":53}," laterVar);\n",[43,2989,2990,2992,2995,2997,2999],{"class":45,"line":98},[43,2991,29],{"class":49},[43,2993,2994],{"class":53}," laterVar ",[43,2996,73],{"class":49},[43,2998,294],{"class":57},[43,3000,79],{"class":53},[126,3002,3004,3013,3038,3045],{"className":3003},[129],[131,3005,3007,3009,3010,3012],{"className":3006},[134],[136,3008],{"disabled":138,"type":139}," Both lines behave identically, logging ",[23,3011,859],{}," in both cases",[131,3014,3016,160,3018,3021,3022,3024,3025,2068,3028,308,3030,672,3033,3035,3036],{"className":3015},[134],[136,3017],{"disabled":138,"type":139},[23,3019,3020],{},"typeof undeclaredVar"," safely returns ",[23,3023,859],{}," for a name that was never declared anywhere (a historic idiom for feature-detection); but ",[23,3026,3027],{},"typeof laterVar",[23,3029,178],{},[23,3031,3032],{},"laterVar",[23,3034,29],{},"-declared later in scope, so referencing it here falls inside its Temporal Dead Zone even under ",[23,3037,951],{},[131,3039,3041,2078,3043],{"className":3040},[134],[136,3042],{"disabled":138,"type":139},[23,3044,178],{},[131,3046,3048,160,3050,3052],{"className":3047},[134],[136,3049],{"disabled":138,"type":139},[23,3051,951],{}," never throws under any circumstances, by design, for any identifier",[199,3054,3055,3057,3072],{},[202,3056,204],{},[206,3058,3059,212,3061,3063,3064,3066,3067,388,3069,3071],{},[209,3060,211],{},[23,3062,951],{}," on a truly undeclared name is safe; but ",[23,3065,951],{}," on a ",[23,3068,29],{},[23,3070,247],{}," name still in its TDZ throws",[206,3073,3074,160,3076,160,3078,3081,3082,3085,3086,3088,3089,3091,3092,3094,3095,388,3097,3099,3100,3102,3103,3105],{},[209,3075,228],{},[209,3077,1246],{},[23,3079,3080],{},"typeof someGlobalThatMightNotExist"," is a long-standing, safe idiom (e.g., ",[23,3083,3084],{},"typeof window !== \"undefined\""," to detect a browser environment) specifically because ",[23,3087,951],{}," was designed not to throw for names that were never declared. However, this safety does ",[666,3090,899],{}," extend to TDZ: if the identifier ",[666,3093,2385],{}," declared later in the same scope via ",[23,3096,29],{},[23,3098,247],{},", the engine already knows about it and considers it \"temporally dead\" until its declaration line, so even the normally-safe ",[23,3101,951],{}," throws. Option D is the common but incorrect belief that ",[23,3104,951],{}," is unconditionally throw-proof.",[3107,3108,3109],"style",{},"html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}html pre.shiki code .sCrzJ, html code.shiki .sCrzJ{--shiki-default:#E36209;--shiki-github-dark:#FFAB70}",{"title":39,"searchDepth":64,"depth":64,"links":3111},[3112,3114,3116,3117,3118,3119,3121,3123,3124,3126,3128,3130,3132,3134,3136,3137,3139,3141,3143,3144],{"id":20,"depth":82,"text":3113},"Q1. What is the key scoping difference between var and let?",{"id":263,"depth":82,"text":3115},"Q2. What is variable hoisting, as it applies to var?",{"id":396,"depth":82,"text":397},{"id":527,"depth":82,"text":528},{"id":685,"depth":82,"text":686},{"id":835,"depth":82,"text":3120},"Q6. What does typeof null evaluate to?",{"id":924,"depth":82,"text":3122},"Q7. What does typeof NaN evaluate to, and what does NaN === NaN evaluate to?",{"id":1072,"depth":82,"text":1073},{"id":1258,"depth":82,"text":3125},"Q9. What is the result of adding a number and a string with +?",{"id":1462,"depth":82,"text":3127},"Q10. What happens when you access a property on undefined, versus declaring a variable with no initializer?",{"id":1595,"depth":82,"text":3129},"Q11. What is the result of typeof applied to a function?",{"id":1743,"depth":82,"text":3131},"Q12. What does 0.1 + 0.2 === 0.3 evaluate to, and why?",{"id":1881,"depth":82,"text":3133},"Q13. What is the type and value of an empty const declaration attempt?",{"id":1988,"depth":82,"text":3135},"Q14. Does const make an object's contents immutable?",{"id":2133,"depth":82,"text":2134},{"id":2229,"depth":82,"text":3138},"Q16. What is the best-practice way to check if a value is NaN?",{"id":2408,"depth":82,"text":3140},"Q17. What is the idiomatic way to handle very large integers that exceed Number.MAX_SAFE_INTEGER?",{"id":2553,"depth":82,"text":3142},"Q18. Which best describes idiomatic use of Symbol?",{"id":2701,"depth":82,"text":2702},{"id":2945,"depth":82,"text":3145},"Q20. What is the best-practice explanation for why typeof is safe to use on a variable that might not be declared at all, but not on one known to be in the TDZ?","md",{},"\u002Fjs\u002F02-variables-and-data-types",{"title":5,"description":39},"js\u002F02-variables-and-data-types","RAjeyieLgHQ_ybiHXsVWq8DzfxZTNeAvqZtMepcHzlg",1787335397331]