Activity › Forums › Salesforce® Discussions › Difference between 'null' and 'undefined' In Apex
-
Difference between 'null' and 'undefined' In Apex
Posted by Anurag algoworks on September 12, 2018 at 1:19 PMWhat is the difference between ‘null’ and ‘undefined’ In Apex ?
chanchal kumar replied 7 years, 9 months ago 5 Members · 4 Replies -
4 Replies
-
Hello,
If you declare a variable and don’t initialize it with a value, it will be null. In essence, null means the absence of a value while if you use variable and not declare it data types then it is undefined.
Thanks.
- [adinserter block='9']
-
Hi,
There is nothing like undefined in apex. we have undefined in case of JavaScript. Instead of asking Difference between ‘null’ and ‘undefined’ In Apex, you can ask what is difference between ‘null’ and ‘undefined’.
JavaScript assigns ‘undefined’ to any object that has been declared but not initialized or defined.
Apex assigns ‘null’ to any object that has been declared but not initialized or defined
Thanks
-
Hi
Undefined means a variable has been declared but has not yet been assigned a value, such as:
var TestVar;
alert(TestVar); //shows undefined
alert(typeof TestVar); //shows undefinednull is an assignment value. It can be assigned to a variable as a representation of no value:
var TestVar = null;
alert(TestVar); //shows null
alert(typeof TestVar); //shows objectTHanks
-
Hi,
There are two special clauses in the “abstract equality comparison algorithm” in the JavaScript spec devoted to the case of one operand being null and the other being undefined, and the result is true for == and false for !=. Thus if the value of the variable is undefined, it’s not != null, and if it’s not null, it’s obviously not != null.
Log In to reply.