Difference Between undefined & null
undefined
undefined
- It is type defined for variables where value is not defined during compile time
- Compiler uses 'undefined' as type for variables that are not defined with value
- "undefined" keyword is used to check whether value is defined or not
Practical Approach:
In above code value of price is not supplied during compile time so price will be undefined..see output
If we use 'undefined' keyword in 'if statement' then output will be according to condition
null
- Null is type defined for variable when value is not defined during runtime
- Variable is not supplied with value during runtime and you are trying to use variable then it returns null
- null is exception type used to tell that there is no value
- we can verify the null type by using the keyword "null"
Practical Approach:
In above code if value of name is not supplied during runtime then output will be like below
If we use 'null' keyword in if else statement then output will be according to condition
Posted By: pankaj_bhakre
No comments:
Post a Comment