PDF In-Depth

Forms - More About JavaScript Types

February 01, 2001


Data types are implicit and (to a degree) contextual in JavaScript, which makes life easy on the programmer, for the most part. But there are times when it is helpful or even essential to know whether two variables are of the same type. In recognition of this, the folks who certify and modify the core language have introduced a new operator (or pair of operators) that, while not in the version of JavaScript used in Acrobat 4.0, will without a doubt be in the next version of Acrobat JavaScript. I am talking, of course, about the strict-equality operator. Some people call it the "identity operator," but I prefer the term strict equality, which to me is just as strict (!) and more descriptive since it admits the possibility of a not-so-strict equaity operator (which is in fact what we're all accustomed to using now).

In JavaScript 1.3 and 1.4, the strict equality operator looks like three equal signs in a row. You can use it to test things like:

if (1 === '1')   app.beep(0);

In real life, you wouldn't test a statement like that one, necessarily. I chose it because it illustrates a point. The point is that currently, if you do:

if (1 == '1')   app.beep(0);

you will get a beep, because with the less-strict equality operator (that we're all accustomed to using), the comparison is permissively type-resolved. That is, JavaScript converts the string to a number and then does the comparison. Whereas, with the strict-equality version (further above), the comparison fails because the items being compared are of different types. Naturally, there is also a strict inequality operator, !==, which can be used in much the same way and circumstances as the strict equality operator. Again, if the parameters differ in type, !== will return true on that basis alone.

So, if you want to compare two items by value, just use == or != per usual. If you want to compare them by value and type, use === or !==. But don't use these latter two yet, because they don't work in Acro 4. (You'll get a syntax error.)

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.