JavaScript - Values,Types, Operators. Things that you should not take lightly.

Understanding the behavior of operators on values is an important aspect every beginner should take care of. Doing so will not only help you in the longer run but also help you understand certain unexpected behavior your code might put forward to you. While learning any programming language it is quite common that you might skip the fundamentals and directly dive into advance concepts and start writing code. Well, that can prove good for some who has good grasp and observation skill, it is not recommended for the others.

In this post we will be looking at values and understand how they constitute what we call as data. Then we will discuss data types which are nothing but categorization of values into different types such as Numbers, String, Boolean etc. Now we have the basic building block and then we look into the manipulation of data types using operators.  

VALUES

When you type your name into a program the computer stores it in the form of bits. So anything meaningful that you would like to operate upon or store into the computer can be called as a value.
Which implies, the string "Hello World" is a value, your favorite character in a book named "Nicholas" is a value, your street address "No.11 Baker Street, St. Marks Road" is a value. My telephone number 5499002234 is a value, your date of birth "01 APR 1990" (that was on purpose ;) ) is also a value.
Now the question that arises is, How do we manipulate values. We definitely need to process them or run our program over them such that we can get some useful done. There is no point in simply typing lot of values into the computer. This is where we come across Data Types that we need to classify different values and thereby perform operation over them.

DATA TYPES

Continuing from top, we are trying to understand to need for Data types. So when we have values classified into predetermined types it is easier to perform certain action over them. For example, the program knows when we write a statement to multiply a  Number Data Type with another number. There is no confusion. And if you try and multiply the string character with a number the JavaScript engine executing the code can throw error at you.

There are six basic types of values in JavaScript: numbers, strings, Booleans, objects, functions, and undefined values.

Examples of each value types or (Data Type) is as follows

Numbers : 1,
                  0,
                  256998,
                  3.2363521,
                  7.022,
                  1.456e20.

String : we have discussed in the earlier passage. String have a specialty, that is, they are denoted using single or double quotation marks.

Boolean : These can have only two Values, that is, True or False

Then we have objects and functions that are out of scope of this post. We will looking into those two in detail in future posts.

We also have the undefined value type which basically null or nothing. this happens when you have a variable declared but no value has been ever passed to the variable. Now when you try to find out the data type of the variable using the unary operator "typeof" you get the return value as "undefined" which basically means the variable doesn't have anything stored in it. undefined and null mean the same thing the only difference being null is not a type but a value.

All this may seem confusing but if you open a text editor and execute sample code on a browser it might be a little more convincing. Also, watching the video might give you a little more clear idea about the things that we have discussed.

OPERATORS

There are different group of operation that JavaScript has got to offer us.

1. Arithmetic operators that include the (addition), (subtraction), (multiplication),  /  (division),  (remainder) operators.

2. Comparison operators or what is called the Relational operator such as <(less than), >(greater than) etc.

3. Unary operators, the minus sign that can be used to negate values and the 'typeof' operator which returns the data type of the value that is passed to it.

4. Logical operator includes the && (AND), || (OR), ! (NOT).

This has just scraped the fundamental part of JavaScript manges data types and the operations performed over the data using operators. The above explanation has been elaborately explained with the help of live execution of the JavaScript code on a browser. We will looking at how JavaScript assigns data types performs operations by producing the output into the console window.

You will just need a latest browser such as Chrome or Firefox and NotePad (since I am on a Windows PC) or any text editing software that you are comfortable with.

Popular posts from this blog

What really is a Hypertext?

Browser Rendering Phase

Crypto crypto everywhere but not a token to bet your life on