DEV Community

Cover image for Chapter 1 : Values and Their Operators in Javascript
Kumar Shubham
Kumar Shubham

Posted on

Chapter 1 : Values and Their Operators in Javascript

Values

If you are familiar with any programming language, then you must have heard about values and values in JS are more or less similar.
Values are nothing just types of data that can be stored in system.

Types of Values

1.Number

Values of the number type are numeric value. In a JS program they are written as :
91,23.5

For very big number scientific notation is also used, like 3.997e8 which is equal to 3.997 * 10^8

Now we know how the numbers are stored in system but these are of no use if we can't perform any meaningful operation on them.
One of most important operation is Arithmetic Operation.
In Arithmetic Operation, we perform simple Multiplication or addition and a new value is produced from them.
E.g- 10+4*3
Here an arithmetic operation is performed on numbers. + and * are operators.

Special Numbers

There are 3 values in JS that is considered to be Special Numbers

  • Infinity
  • -Infinity
  • NaN

Infinity and -Infinity are respectively greatest positive and negative number possible. NaN stands for Not a Number. When we perform any numerical operation on data that does not yield any meaningful result it will give NaN. For example- 0/0 yield NaN.

2.Strings

Strings are used to store text. Text must be enclosed in quotes.

'I am string'
"I am String"
`I am String`
Enter fullscreen mode Exit fullscreen mode

Two strings can be concatenated using +

'I'+ 'am' + 'String'
Enter fullscreen mode Exit fullscreen mode

3.Boolean Values

Boolean values are just true and false.
If we check some condition and it's true the it return true otherwise false.

console.log(5>6)
// false
console.log(5<6)
// true
Enter fullscreen mode Exit fullscreen mode

Don't worry about console.log , this is nothing just a way to see output. More on that later in other in next blogs.

<,>,=,<=,>= are Comparison Operators and have same functionality as in Mathematics.
!= is also an Conditional operator and it is used as not equal to. if we write a!=b, this means a is not equal to b.

Logical Operators are operators that can be performed on boolean types. They are AND,OR and NOT.
AND is binary operator(need two value to perform operation) written as && and it yield true iff both values given to it are true.

console.log(true && true)
// true
console.log(true && false)
//false
Enter fullscreen mode Exit fullscreen mode

OR is also binary operator written as || and it yield true if at least any one of two given values are true.

console.log(true || true)
// true
console.log(true && false)
//true
Enter fullscreen mode Exit fullscreen mode

NOT is a unary operator written as ! and it reverse the boolean value.

console.log(!true)
// true
console.log(!false)
//true
Enter fullscreen mode Exit fullscreen mode

4.Empty Values

There are 2 Empty Values null and undefined. These two are personally value but does not have any value assigned to it.
They are used to denote the absent of meaningful data.
null is an assigned value but it means nothing.
*undefined * means a variable is declared but not defined yet.

If you feel uncomfortable understanding null and undefined, give it some time. As you know more about JS, it will become clear.

This blog is part of reading and writing blog for each chapter of eloquent Javascript book challenge, started by Tanay Sir. Follow him for more great contents.

Blog Post of 2nd chapter is coming soon.

Top comments (0)