Quality Learning Support For All
First time here? Checkout the FAQs!
x
0 like 0 dislike
107 views

What's the difference between a variable that is: nullundefined or undeclared?

How would you go about checking for any of these states?

in Data Science & Statistics by Platinum (95,868 points) | 107 views

1 Answer

0 like 0 dislike

From what I understand, in Javascript, undefined and null are somewhat related on what value a variable contains. The case for undeclared differs. It tackles on how a variable is defined and how javascript treats these variables. So I am going to discuss undefined and null first since both are on Data Type category.

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.

ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures

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).

ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var

by Platinum (95,868 points)

Related questions

1 like 0 dislike
1 answer
0 like 0 dislike
0 answers
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
0 answers
0 like 0 dislike
1 answer
1 like 0 dislike
0 answers
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Sep 3, 2019 in Data Science & Statistics by MathsGee Platinum (95,868 points) | 67 views
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
0 like 0 dislike
1 answer
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
1 like 0 dislike
0 answers
asked Sep 13, 2020 in Mathematics by MathsGee Platinum (95,868 points) | 34 views
0 like 0 dislike
0 answers
0 like 0 dislike
1 answer
asked Apr 28, 2020 in Mathematics by MathsGee Platinum (95,868 points) | 117 views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Sep 5, 2020 in Physics by Student SIlver Status (10,378 points) | 70 views
Join the MathsGee Q&A learning community and get support for business success - MathsGee Q&A provides answers to subject-specific questions for improved outcomes.

On the MathsGee Q&A learning community, you can:


  1. Ask questions
  2. Answer questions
  3. Comment on Answers
  4. Vote on Questions and Answers
  5. Donate to your favourite users
  6. Create/Take Live Video Lessons

Posting on the MathsGee Q&A learning community


  1. Remember the human
  2. Behave like you would in real life
  3. Look for the original source of content
  4. Search for duplicates before posting
  5. Read the community's rules

MathsGee is Zero-Rated (You do not need data to access) on: Telkom |Dimension Data | Rain | MWEB

MathsGee Tools

Math Worksheet Generator

Math Algebra Solver

Trigonometry Simulations

Vectors Simulations

Matrix Arithmetic Simulations

Matrix Transformations Simulations

Quadratic Equations Simulations

Probability & Statistics Simulations

PHET Simulations

Visual Statistics

Visual AI

Management Leadership | MathsGee ZOOM | eBook