[thelist] Assignment Question

Jason Handby jason.handby at corestar.co.uk
Sun Sep 12 05:42:06 CDT 2010

Hi Judah,

> For what it's worth, I don't believe that Javascript actually has this
> operator (though Java does).

I checked my copy of "JavaScript: The Definitive Guide" 4th edition
before I sent the email, just in case :-)

It's also in the ECMA specification. And I just tried a little test of
it that worked in IE8 and the latest Firefox.

	function doSomething()
		var n = 0;
		n |= 2;
		n |= 8;
		n |= 64;
		alert("Result is " + n);

(It should pop up 74.)

I can't imagine it's something that JavaScript programmers use a lot,
though - and possibly for that reason there seem to be a few websites
that don't mention the bitwise assignment operators, including
(unfortunately) the wikipedia page on JavaScript syntax.

But if you're implementing a C-like language, and you've already got the
| operator, it's probably pretty easy to implement |= . All of those
compound assignment operators work in the same way, so once you've
written one it's probably easy to add the rest of them.

Oh and I just discovered that ActionScript has it too, which makes sense
I guess because of its roots in Javascript.

> Coldfusion (which I primarily work in)
> also does not have that operator. Interesting, I've not run across it
> before.

Ah now you've got me there. I have no idea what Coldfusion scripting
even looks like, despite being on this list for a while. I guess I must
have tuned it out!


More information about the thelist mailing list