JS Interview Question: What’s the difference between a variable that is: null, undefined or undeclared?
What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?
undefined is a variable that has been declared but no value exists and is a type of itself ‘undefined’.
null is a value of a variable and is a type of object.
We use ‘console.log();’ and ‘type of’ to check if a variable is undefined or null.
undeclared variables is a variable that has been declared without ‘var’ keyword.
testVar = ‘hello world’;
as opposed to
var testVar = ‘hello world’;
When former code is executed, undeclared variables are created as global variable and they are configurable (ex. can be deleted).
If you are looking for a platform to develop your clients’ website, check out my SAAS platform https://ecompurpl.com :)
EcomPurpl.com is the all-in-one solution for anyone looking to create a website. Templates, E-Commerce, Hosting, Galleries, Booking & Appointments, CRM, 24/7 support, and integration of your app are all included.