The Complete JavaScript Guide 2020 – Part 2

When it comes to computers, the only thing that matters or even exists is data. You can read, create and even modify data but all the operations that happen can…

When it comes to computers, the only thing that matters or even exists is data. You can read, create and even modify data but all the operations that happen can happen only on data.

All this data is stored in terms of binary values called Bits, usually represented by 0’s and 1’s, the language of computers.

Therefore all the data that you enter into your machine, is first converted into this binary data and then interpreted by the system.

Now, whenever you come across a screen like this in a movie, all these 0’s and 1’s are what basically amounts to a lot and a lot of data.

Though programmers don’t really code in binary, and this is just a way to make it look exciting, in fact, coding doesn’t really look that exciting but you can still make pretty decent things.

So now that we know how data looks like, imagine going through that screen and trying to figure out what the hell is going on?

To be able to work with these huge amounts of bits, we need to group these bits so that they can represent a certain type of information. In JavaScript, these groups are called Values.

Each Value has a type that determines the kind of data it represents, it may represent a number, it may represent text, and so on.

There are a few primitive data types when it comes to JavaScript and they are:

  1. Number
  2. String
  3. Boolean
  4. Null
  5. Undefined

There is also Symbol and BigInt but we will not be talking about them here, so let’s start.

Numbers

Numbers are pretty much what it says, it is a way of storing or representing a number in JavaScript.

Some languages store different kinds of numbers like positive numbers, negative numbers, decimals differently but in JavaScript, there is only one number type.

It’s just called number.

It can store, positive numbers, negative numbers, whole numbers, integers, decimal numbers often called floats.

I’ll be using the google chrome developer tools to showcase some of the code and if you are new to chrome or haven’t really heard about developer tools before.

Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately helps you build better websites, faster.

Now we want to open the console for this so you can do that by pressing Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, Chrome OS), we can write javascript directly into the console.

So now that we know we can use numbers in JavaScript, on their own they aren’t very useful, just typing a number and getting it back to us is not really useful to us.

What we can do with numbers, are some basic arithmetic operations, it is basically like a calculator, that’s definitely a bit more exciting than just getting the numbers back, we have finally done something with the numbers that we had.

Apart from Basic Mathematical Operations like the ones shown above, JavaScript also follows the standard order of operations which we are taught in school like BODMAS for my Indian fellows or PEMDAS or any of the other mnemonic which is followed in the world, they generally follow the same order and so does JavaScript.

Another Special case when it comes to numbers in JavaScript is NaN or Not A Number.

In fact, NaN is a number in JavaScript, it is considered a numeric value that represents something that is not a number.

I know, it still confuses the hell out of me as well.

We can get NaN if we do an arithmetic operation with NaN itself, the result would be NaN or if we divide zero by zero.

Before we end the topic of numbers let me introduce you to some more values which are Infinity, Negative Infinity, Zero, and, Negative Zero.

So there is no number to showcase infinity in JavaScript and it just referenced to as Infinity.

String

A string is basically a textual piece of data, that’s it.

If you want to write any piece of text, it is identified as a string. The only rule is that it needs to be surrounded by quotes.

We have three types of quotes:

  1. Double Quotes: “Hello”
  2. Single Quotes: ‘My Name is’
  3. Backticks: `Vibhor`(Not to be confused with single quotes, backticks are generally the ones above the tab key on a standard keyboard)

Now if you are used to some other languages like C, you will note that there is no special character type, for instance, char in C.

There is only one type present in JavaScript and that is String.

Boolean

In simple terms, it is used to identify whether something is true or false and thus Boolean has only two values.

It is used to store yes/no values, true if the evaluated expression is correct or false if the evaluated expression is incorrect.

Now if you are confused why ‘a’<’C’ gave the answer as false, simply because the system is not recognizing them as letters but as values, and when converted into values the value of ‘a’ is 

97 and the value of ‘C’ is 67. These are called ASCII values, you can read more here.

Null 

The special value of null defines “nothing”, “empty” or “value unknown” in JavaScript.

Unlike in other languages, it doesn’t refer to a null pointer or a non-existing object, it is a special type of its own which holds only null value.

In the above example, it only states that name is empty, thus null.

If you have no idea what ‘let’ or ‘name’ means, name is a variable that holds the value of null. I will cover variables in detail in the next section of this guide.

Undefined

Undefined is a bit different from null, where null states that the value is empty, undefined means that the “value is not assigned”

It has yet to be given a value.

And Done!

That’s pretty much the basic gist of value types in JavaScript. So you can definitely open up the console and explore more around the topic and have a go at it!

Find the Guide Map

Follow me on my social – LinkedIn, Twitter, Discord

Related Posts

Arrays in Javascript

Arrays in Javascript

If you have ever learned about the basics of programming you must have come across arrays, they...

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *