A Little More on Nothing

VBScript has Null, Empty and Nothing.  What about JScript?  Unfortunately, JScript is a little screwed up here.


Like VBScript, in JScript an uninitialized variable is a VT_EMPTY variant.  To check to see if a variable is undefined, you can say


typeof(x) == "undefined"


There is a built-in Empty constant like in VBScript -- in JScript it is undefined.


If you say


var x = null;



then you get "object", so you might expect that null is the JScript equivalent of Nothing -- an object reference that refers to no object.  From a logical perspective, you'd be right.  Unfortunately, for reasons which are lost to the mists of time, JScript implements a null variable internally the same way that VBScript implements a Null variable -- VT_NULL, the "data is missing" value.


This poor decision leads to two problems.  First, JScript does not interoperate very well with COM objects which have methods that can legally take a Nothing but not a Null.  (I believe that Peter Torr has some addon code that adds this capability to JScript.) Second, JScript processes Null variants passed into it as though they were object references, not database nulls.  Thus JScript does not implement any of the rules about Null propagation that VBScript implements.


We corrected these problems somewhat in JScript .NET.  JScript .NET uses a null object reference to internally represent null, and can manipulate DBNull objects, so the interop problems go away.  However, JScript .NET still does not implement the null propagation semantics for mathematical operations on database nulls.

Comments (7)

  1. Ed Ball says:

    Just wanted to say that your blog is far and away the most useful and probably the most interesting blog that I read. Our client application uses IE+DHTML+JScript extensively; we’ve had to learn a lot of this stuff the hard way. We’ve learned over time that JScript is an amazingly powerful language, and it is usually a joy to work with, though a compiler/lint/something to help catch spelling errors before runtime would be handy. 🙂

  2. Eric Lippert says:

    Thanks, that’s a nice thing to say.

    If you have any questions or ideas about things you’d like to see in future posts, feel free to send them my way.

    As for detecting undeclared variables at compile time — unfortunately in JScript Classic and VBScript that’s pretty much impossible due to the way the browser works. Coincidentally, I was planning on posting why exactly that is later this week, so watch this space.


  3. Peter Torr says:

    You can always try passing your code through JSC (the JScript .NET compiler) as some sort of "lint" program. You may have to artificially declare all the IE globals you use (like ‘window’) or you can use /fast-

  4. Lance England says:


    I also wanted to tell you how incredibly educational your blog is. It has shot to the top of my "must read" list. Your writing style is great. You really do a nice job explaing technical subject matter in a way that is easy to understand. Keep up the great work!

  5. Eric Lippert says:

    Thanks Lance. One does one’s best.

    Like I said, if you have any ideas or questions for future posts, feel free to send them my way. (Note though that I have 24 items on my ever-growing list of potential future topics, so I might not get to new ones right away…)

  6. quasiperfect says:

    I’m encouraged that JScript.Net improves Jscript where it’s weak. But does it break it where it’s strong? Is there any way to shoehorn JScript.net into the windows script component framework? I am most concerned about the absence of "option explicit" (vbscript) and the abscence of "use strict(true)" (javascript 2.0) in the implementations of plain JScript that I’ve tested. Thanks the great commentary. Regards, JPK

  7. Jay Zhang says:

    Another problem with JScript.Net is that it seems that MS .Net support for script engine (VSA) has limited the typeof usage in JScript.Net.

    For instance,  in JavaScript you can pass undefined argument to typeof without problem:


    But if same code is run in VSA implemented script engine, you’ll get a compilier error. You have to do something

    var x;

    if (typeof(x) != "undefined")


    In this case what is the point to even have that return value "undefined" if a argument has to be defined or declared first.

    Any comment can send to Jay.Zhang@datamaxx.com

Skip to main content