Brain Effing Javascript

Brain Effing Javascript

Javascript has always been fascinating to me in so many ways, because it packs in so many things for a language that has been developed in 2 weeks (there were improvements after that). Look at this


var truthy = true; 
 if(truthy === !+[]){ 
 	console.log("It's Truthy"); 

Put this in the console and it prints the value. It’s ’cause

!+[] === true

javascript interprets the combination of these special characters into actual values. Similary

!!+[] === false

And also you can get numbers like this

+[] === 0 +!+[] === 1 !+[]+!+[] === 2 ....

We can create all the numbers by adding !+[] like that. Using this, if you want your fellow programmer to go mad you can do something like this


var l = +!+[]; 
 for (var i = +[]; i <= !+[] + !+[]; i++) {
 	l = l + (+!+[]); 

with these special character combinations, a complete program can be written in javascript.

Further reading:


Vetrichelvan Jeyapalpandy

12 years of experience in web development. Javascript enthusiast. Performance is an important trait of any website, so trying to improve that wherever possible.

View Comments
Next Post

Conversions in Javascript

Previous Post

jQuery AnimationEnd Plugin - Provides a callback when a CSS3 animation is complete on an element