Frontend Fundamentals 1/20

After some advice from well-meaning peers, I’ll try to study 10 items a day as part of efforts to improve my basic skills. In the past I have studied some topics, and it did somewhat help me solve problems quicker at work. For an initial target, I’ll t…


This content originally appeared on DEV Community and was authored by ZhiHong Chua

After some advice from well-meaning peers, I'll try to study 10 items a day as part of efforts to improve my basic skills. In the past I have studied some topics, and it did somewhat help me solve problems quicker at work. For an initial target, I'll try to study for 20 days, and save 10 days for recap.

Note: I still have great faith in ChatGPT to perform the fundamental work for me though. So there's that.

1. What is the difference between null, undefined, and undeclared? How would you go about checking these states?

Undeclared means it's not even initialised with a let, const or var. undefined means it's declared but no values were initialised. null means it is declared and specifically set to null.

I think you can't tell between undeclared and undefined, unless there was some way of checking all memory locations to see whether a certain variable name has been defined? But between null and undefined, we can first check if var === null. If that check fails, we check if !var to find if it's undefined. The order matters. If these two checks fail, then it's probably defined and non-null.

Model Answer
Interesting things from the answer to explore:

  1. equality operators (== / ===) - this is something that seems fundamental but possibly confusing.
  2. As a good habit, never leave your variables undeclared or unassigned. Explicitly assign null to them after declaring if you don't intend to use them yet. - I think undeclared variables can cause problems, yes, that's why we always have fallback values, such as - for display string, or 0 for numbers. Actually linting rules (?) help avoid this as well. Feels like leaving it undefined is still acceptable though.

2. Practice implementing type utilities that check for null and undefined on GreatFrontEnd.

Question here.

3. Practice implementing type utilities (II): Non-primitives

Question here.


This content originally appeared on DEV Community and was authored by ZhiHong Chua


Print Share Comment Cite Upload Translate Updates
APA

ZhiHong Chua | Sciencx (2025-01-28T02:29:23+00:00) Frontend Fundamentals 1/20. Retrieved from https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/

MLA
" » Frontend Fundamentals 1/20." ZhiHong Chua | Sciencx - Tuesday January 28, 2025, https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/
HARVARD
ZhiHong Chua | Sciencx Tuesday January 28, 2025 » Frontend Fundamentals 1/20., viewed ,<https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/>
VANCOUVER
ZhiHong Chua | Sciencx - » Frontend Fundamentals 1/20. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/
CHICAGO
" » Frontend Fundamentals 1/20." ZhiHong Chua | Sciencx - Accessed . https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/
IEEE
" » Frontend Fundamentals 1/20." ZhiHong Chua | Sciencx [Online]. Available: https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/. [Accessed: ]
rf:citation
» Frontend Fundamentals 1/20 | ZhiHong Chua | Sciencx | https://www.scien.cx/2025/01/28/frontend-fundamentals-1-20/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.