Let's get started then.
Queues are the abstract data structure, in which items are kept in a specific order. The items are added from the back to the queue and taken out from the front of the queue.
The above image describes the queue very well. You can see two terms in it -
dequeue. Let's know what these are
- When an element is pushed to the queue, the operation is known as
- When an element is popped out of the queue, the operation is known as
A queue can also be seen as an array, with some restrictions.
The following example will help you understand it better
var arr = [1, 2, 3]
Adding a number to the end of an array can be done with
push() method. Similarly popping out from the front of an array can be done using
arr.push(4); // enqueue, now array [1, 2, 3, 4] arr.shift(); // dequeue, now array [2, 3, 4]
Boolean can only have two values which are either
==. It compares two values and returns either
To compare two different data types(for e.g.
string), it must convert one type to another. This is known as Type Coercion.
Some examples of equality operator are
1 == 1 // true 1 == 2 // false 1 == '1' // true "3" == 3 // true
As you may notice, the last two examples return
true irrespective of different data types i.e. this operator does not check for equality of data types.
Strict Equality Operator
Strict Equality operator is represented by
===. This not only checks for the value but also checks for the data type of its two operands. Let's see an example
4 === 4; // true "4" === 4; // false
The second comparison returns
"4" is a string while
4 is a
typeof "3"; // returns 'string' typeof 3; // returns 'number'
It is the opposite of the equality operator. It returns
true when two values given to it are not equal,
false otherwise. Just like the equality operator, it doesn't check for the data type of its operands.
Some examples of it can be seen as
1 != 2 // true 1 != "1" // false 1 != true // false 0 != false // false
Strict Inequality Operator
This would be clear by now. Strict inequality operator is represented by
!==. This not only checks for the value but also for the data type. It is just the opposite of the strict equality operator. Let's understand its usage with some examples:
3 !== 3 // false 3 !== '3' // true 4 !== 3 // true
As you may notice, that the second case returns
true because the data type for the values is different.
It is highly advisable to use strict equality and strict inequality operator instead of their non-strict options available.
Greater than operator (
It compares two values and returns
true if the value to the left of it is greater than the value to the right. One thing to note down here is that it converts the data type of the values before comparing, just like the equality operator.
A few examples can be
7 > '3' // true 2 > 3 // false '1' > 9 // false
Greater than or equals to operator (
It checks if the value to the left of it is either greater or equal when compared to the value right of it.
7 >= '3' // true 2 >= 3 // false '7' >= 9 // false
Less than operator (
It is quite obvious now. It checks if the value to the left of it is lesser than the value to the right of it. Returns
true if so,
'3' < 7 // true 3 < 2 // false '8' < 4 // false
Less than or equals to operator (
Let's directly go with an example for this
5 <= 5 // true 3 <= 2 // false '8' <= 4 // false
With the end of this short post, we have acquired some knowledge about the Boolean data type and Queue data structure. Apart from it, we found out about type coercion and how they work when used with comparison operators.