Saturday, November 15, 2014

TIL: Plowing through the basics of JS actually helps

Today, I read through some pages of "JavaScript, the definitive Guide". I knew most of the stuff. And once again, like in almost every language, I read trough the seemingly boring bitwise operators. You know, stuff like |, &, ~, ^ and bit shift operators >>, << and >>>.

So I asked myself, why should I use them? Being and not-too-young developer and not having used them in any real-world-application yet, this shows me: Either those bit operators are a little bit outdated or I am a little bit ignorant, that means that I could miss out simpler solutions than I usually provide.

So I decided that I have to learn some bit operation magic.

So beside bit shift operations as an alternative to multiplying or dividing by powers of 2, I learned, that | 0 converts nearly everything to an integer.

Longer description can be found here:

So, if you have some handy trickt with bitwise operators in JavaScript, let me know.

The other thing I heave learned: labels in Javascript. You can label stuff. Most likely, you will label loops, so that you can break free from them with with the break label; statement.

I have to say, that Mozilla discourages you from using labels.

No comments:

Post a Comment