Values, Data Types and some operators

Bashir Hamza
Netscape
Published in
4 min readSep 13, 2017
CREDIT: www.shutterstock.com

JavaScript has grown to be one of the worlds most powerful languages and has earned the spot of “write once run everywhere”. it has become very useful for many many purposes and has had so many libraries and frameworks built upon it. Virtually every programmer wants to learn it, but the best way to learn JavaScript is usually by learning vanilla Js first so as to understand basically how JavaScript works before diving into any frameworks. This prompted me to write an article to help us better understand how values,types and a few operators work in JavaScript. This is a very basic knowledge that every JavaScript programmer should know and be conversant with.

Data

Generally, a computer system consists only of data and anything that isn't data in a computer just doesn't exist. The computer represents data in a form called bits. Bits are any kind of two-valued things, usually described as 0s and 1s. Bits in general control the life span of computers in which they take forms such as a high or low electrical charge, a strong or weak signal and many others. Any piece of discrete information can be reduced to a sequence of zeros and ones in which the computer represents as bits. When you input a number say 9 and store it to memory, the computer doesnt store that exact 9 in memory but instead stores it as its bitwise equivalent which is 1001.

Values.

Imagine a random number of multiple bits that you want to maybe analyze and make some sense out of, the best way to go about this would be to take them portion by portion in which you will analyze and later give out your conclusion after everything. these portions are referred to as values. even though they are all made of bits, all values have a type that determines the role that it plays in the computer system. JavaScript classifies values into 6 basic types which are numbers, booleans, strings, objects, functions and undefined values. so now lets talk a bit(pun intended) about these types.

Numbers.

These are values represented as normal numeric values that the computer stores in its memory in bits. JavaScript uses a fixed number of bits,about 64 to store a single number value. this means that the total amount of numbers that can be represented in JavaScript are of course limited because of the value above. For N decimal digits, the amount of numbers that can be represented is 10 . Similarly, given 64 binary digits, you can represent 264 different numbers, which is about 18 quintillion (an 18 with 18 zeros after it). i think this should definitely be enough. The main things in which we use numbers for is arithmetic where we can add, subtract, multiply, divide and do a bunch of other manipulations which take two or more numbers and manipulate it and give an output. These are represented as operators which take the form of *(multiplication), +(addition), -(subtraction), /(division).

an example of a use case is

10 + 14 * 1

but there is a rule to how they are manipulated. When operators appear together without parentheses(those in parentheses always take precedence), the order in which they are applied is determined by the precedence of the operators. The example shows that multiplication comes before addition. The / operator has the same precedence as *. Likewise for + and -. When multiple operators with the same precedence appear next to each other, as in 4–3 + 1, they are applied left to right: (4 - 3) + 1.

Another operator which might seem abstract is the % operator which just means to get “the remainder of”. example is 14 % 2 gives 0. this sign is pronounced as modulo

Special numbers

There are three special values in JavaScript which are considered numbers but they do not behave as normal numbers do. The first two are Infinity and -Infinity, which represent the positive and negative infinities. The third one is called NaN which stands for “not a number”, even though it is a value of the number type. You’ll get NaN when you try to calculate 0/ 0 (zero divided by zero), Infinity — Infinity, or any other which their results do not make sense.

Strings

Strings are a type of data used to represent text. They are written by enclosing their content in either single or double quotes.

“ I am a boy “
‘she is 2 years old’

But there are some limitations with th, imagine how putting quotes between quotes might be. Newlines(the characters you get when you press Enter) also can’t be put between quotes. To make it possible to include such characters in a string, a backslash (\) is used which indicates that the character after it has a special meaning. This is called escaping the character. A quote that is preceded by a backslash will not end the string but be part of it. When an “n” character occurs after a backslash, it is interpreted as a newline. Similarly, a “t” after a backslash means a tab character. and many others that you can go and research on.

Boolean values

This is a data type used to distinguish between two possibilities,
like “yes” and “no” or “on” and “off”. It has just two values: true and false (in which you write simply as those words). You can use this to check comparison(example: > and <) and also with some logical operators(&& and ||)

use case

console.log (3 > 2) //!trueconsole.log (3 < 2)//!falseconsole.log ( true && false ) //!falseconsole.log ( true && true ) //!true

Undefined values

JavaScript has two special values called null and undefined,these are used to
represent the absence of a meaningful value. They are also values, but they carry no information. The difference in meaning between undefined and null is an accident of JavaScript’s design, and it doesn't matter most of the time. They can be used interchangeably.

Thank you.

--

--