Values and Their Operators in Javascript.

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 the system.

Types of Values

1. Number

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

For very big numbers, 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 the system but these are of no use if we can't perform any meaningful operation on them. One of the 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 are considered to be Special Numbers

  • Infinity
  • -Infinity
  • NaN

Infinity and -Infinity are respectively the greatest positive and negative numbers 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`

Two strings can be concatenated using +

'I'+ 'am' + 'String'

3. Boolean Values

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

console.log(5>6)
// false
console.log(5<6)
// true

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

<,>,=,<=,>= are Comparison Operators and have the same functionality as in Mathematics. != is also a 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 a binary operator(need two values to perform the operation) written as && and it yields true iff both values given to it are true.

console.log(true && true)
// true
console.log(true && false)
//false

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

console.log(true || true)
// true
console.log(true && false)
//true

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

console.log(!true)
// true
console.log(!false)
//true

4. Empty Values

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