Unknown Kept Facts about the Flourishing Language JavaScript


JavaScript Bundled Up With Secrets

JavaScript has been the most functional and complexed programming language that has world ever seen. Where everything is kept in the Nullspace and functions are bundled up in numerous scripts. Pablo Picasso must be very proud of his invention.

Well, this article is not about the greatness and achievements of JavaScript language. In this post, we want to discuss some hidden and kept secrets of the JavaScript. As this lucrative programming language has plenty of unknown features that international developers are not fully aware of.

So, guys, gear up your shoes as you are about to read few lesser-known facts about JavaScript language. And, we truly hope that by the end of this post, you will have some secrets revelling experience ahead of you.

#1. NULL Is An Object

Okay, so let’s start with our favorite NULL feature of the JavaScript. Null is the biggest oddity and an object of the JavaScript language. Now, you must be wondering that null is a void and doesn’t holds any value, then why the heck we are saying that a null is an object. Well, let us show you something:

alert(type of null); //alerts ‘object’

But, still, the null isn’t considered as the instance of the object. As you might not know that in JavaScript every value is an instance of base object. So, like this every number is the instance of number object and every object is the instance of object object. And, this leaves us with the movement of clarity, thus null is the absence of value, then it can’t be the instance of anything. This makes the following statement false.

alert(null instance of Object); //evaluates false

#2. NAN Is A Number

If your heard is already hurting after reading about the null being an object, then take your medication immediately. Because nan stands for “not a number” is actually a number. Confused, see this example:

alert(typeof NaN); //alerts ‘Number’

alert(NaN === NaN); //evaluates false

Moreover, nan isn’t considered equal to anything. The only way to find the value of nan would be by using the function isNaN().

#3. REPLACE() can accept the Callback Function

Now, let’s talk about the much loved REPLACE() function which looks like something this way:

alert(’10 13 21 48 52′.replace(/d+/g, ‘*’)); //replace all numbers with *

This is a common replacement; a string and a asterisk. But, if you want more control over your replacement like when and which number should be replaced. Then, you don’t have to perform much mathematical functions, this can be achieved with the regular expression alone. To obtain this we have to jump to the callback function for each match.

alert(’10 13 21 48 52′.replace(/d+/g, function(match) {

   return parseInt(match) < 30 ? ‘*’ : match;


#4. Regular Expressions Are More Than Match & Replace

Some JavaScript developers assume that regular expressions are all about the match and replace, but guys with a regular expression can do much more. For instance, test () function can be used to verify whether the given sample matches or not.

alert(/w{3,}/.test(‘Hello’)); //alerts ‘true’

The above looks for a pattern of three or more alphanumeric characters, and because the string Hello meets that requirement, we get true. We don’t get the actual match, just the result. Though you can’t reference variable, getting the dynamic pattern is possible with regexp.

function findWord(word, string) {

   var instancesOfWord = string.match(new RegExp(‘b’+word+’b’, ‘ig’));



findWord(‘car’, ‘Carl went to buy a car but had forgotten his credit card.’);

#5. Firefox Reads & Returns Color in RGB, not HEX

Well, we don’t know why Firefox does this, but, it surely knows that anyone interrogating with JavaScript is interested in receiving colors in the hex format not RGB. Example:

Hello, world!



var ie = navigator.appVersion.indexOf(‘MSIE’) != -1;

var p = document.getElementById(‘somePara’);

alert(ie ? p.currentStyle.color : getComputedStyle(p, null).color);


Whereas, most of the browser’s return with ff9900, but Firefox returns with rgb(255, 153, 0) RGB equivalent. Plenty of JavaScript functions are out there available to convert RGB format to hex.

#6. Undefined Can Be Defined

Okay, so let’s end the list on the lighter note, in JavaScript nothing is undefined. The word undefined also stands to define whether the variable is defined or not. For example :

var someVar;

alert(someVar == undefined); //evaluates true

About the author

Arpit Agarwal

I am a freelancer content writer, web developer and Video editor who loves to write technical stuff and on the other hand makes awesome videos as well. I like to make people happy with my writing and also try to make sure, you come back to read more.

By Arpit Agarwal

Most common tags

%d bloggers like this: