Assignment operators in javascript
assignment operator is used to assign values to the variables, if we assign a different value for again and again the operator will assign the values what we finally assign to it.
Example
> a = 10
10
> a = "hello"
'hello'
> a = []
[]
> a = {}
{}
combination of assignment operator with the arithmetic operations
- addition assignment operator ( += )
- subtraction assignment operator ( -= )
- multiplication assignment operator ( *= )
- division assignment operator ( /= )
Comparison Operators
it checks the left and right hand sides values is whether it is equal or it is not equal, wherever want to compare two values in our programs logic. Based on the scenario we not only need use the equality some time we may need not equal less the, greater than and so on, let we see one by one some of the javascript comparison operations
- loose equality ( == )
- strict equality ( === )
- loose inequality ( != )
- strict inequality ( !== )
- greater than ( > )
- less than ( < )
- greater than or equal ( >= )
- less than or equal ( <= )
Logical Operators
it is used to determine the logical flow of program, we may need some time our program want to follow more than one condition on those scenarios we have to check all the condition in this case we can use AND logical operator, some time we have to any one of the condition, other then this we can do NOT operator it will help to check was it is opposite to our specified term.
AND operator ( && )
OR operator ( || )
NOT operator ( ! )
conditional operator
In our program flow whenever we want to do some specific tasks we can do those things in the conditional operator. If we want to run a block of code for specific conditions we can be able to do it, in addition we can add as many conditions as possible.
It looks block by block, we can specify if we want to check all the conditions, any one of the conditions. Whenever the conditions pass it executes the block of code.
Examples
here we are going to check does out values is passes or if not passes
zero = 0;
if ( zero == 0) {
console.log(“here our condition is passes”)
}
here our condition is passes, hence because of our condition passes so it run the block inside the if block
example for opposite case if our condition was not pass
zero = 1;
if ( zero == 0) {
console.log(“here our condition is passes”)
}
using else block
instead of skipping if our if condition fails, suppose if we want to execute any other block whenever our if condition fails in those cases we can use the else block
odd = 1;
even = 2;
if (odd == even){
console.log("they equal")
}
else{
console.log("not equal")
}
NOTE: we cannot use directly without else condition block without if condition block.
we cannot use it directly
else{
console.log("not equal")
}
``
Else if block
up to now we only seen if and else block, if we want to check one then one conditions we can use many if’s along with the else so that instead of skipping that block it check condition and if passes the block will executes
marks = 100
if (mark >= 90){
console.log(“Grade A”)
} else if(mark >= 80){
console.log(“Grade B”)
} else if (mark >= 60){
console.log(“Grade C”)
} else {
console.log(“Grade D”)
}
RCB = 20
CSK = 23
if (RCB > CSK) {
console.log(“RCB wins”)
}
else if(CSK > RCB){
console.log(“RCB wins”)
}
else{
console.log(“DRAW”)
}
marks = 80
attendance = 4
if ( mark => 60 && attendance >= 2 ){
console.log(“PASS”);
}
else{
console.log(“FAIL”);
}
Top comments (0)