DEV Community is a community of 550,695 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

The Rest of the Story: Machine Code and Why Zero is a false-y Value in Javascript

When I was a small boy in the sixties, I would often secretly listen to my small, hand-sized transistor radio under the covers in bed after my parents read me my bedtime story and turned off the lights. I wanted the party to continue, so I would turn in KCBS and listen to the news. One of my favorite radio programs went on at about 9:30pm most nights: Paul Harvey’s “The Rest of the Story.” The pattern of the stories were always the same: a chance meeting, or an odd circumstance that nobody would pay attention to that lead to some very important event or discovery. From tales of the origin of Coca-Cola, or accounts of Elvis Presley’s childhood, Paul Harvey would give you the backstory.

What is Machine Code exactly?

“The Rest of the Story” now brings us to machine code.
Machine code is a computer program written in a way that only a computer can understand. It’s what your Javascript, Ruby, Python or any other “higher-level” language’s code looks like on its way down to the “basement” of the computer’s CPU where it will be processed.

Machine code looks like this:

Machine code is the lowest level of programming detail visible to the human eye. However, machine code is so unreadable that the United States Copyright Office cannot identify cannot identify whether a particular encoded programmed in machine code is an original work of authorship.

As you can see from the image above, machine code is written in base 2 with just two numbers: 1 and 0*.

Think of it: As you look at the image above, each position is either a one or a zero. No other choices.

One or zero

Uno o cero

Eins oder Null

What other binary systems can you think of?

Hot and cold..

“primitive” binary value in our dear Javascript?

Anyone remember Mr. George Boole?

That’s right! Boolean values (Thank you, Mr. Boole!)

You can think of zero as the “off” value which corresponds to false

One is then the “on” value corresponding to true.

So Javascript has “remembered” Machine Code toiling away in the “basement” of the CPU. We can imagine JS wanting to make Machine Code’s life a little easier by keeping zero as a false-y value as Machine Code would interpret zero in its own language.

And now you know the rest of the story.

And For Good Measure:

In 1995 Brendan Eich was working at Netscape Communications Corporation and wanted to put a language into the browser. The language was first called Mocha and then renamed to LiveScript. A few months later Netscape and Sun Microsystems did a licence agreement and called the new language JavaScript. The idea was to make it a complementary language to go with the already existing and popular Java. Some said it was also a marketing ploy meant to ride on the coattails of the very popular Java programming language.

*Machine code can also be expressed in a hexadecimal format(base 16)