Skip to content

Instantly share code, notes, and snippets.

@foysalimran
Created March 24, 2018 16:32
Show Gist options
  • Save foysalimran/a6542ae3d14bc91d69bbd95d4986477d to your computer and use it in GitHub Desktop.
Save foysalimran/a6542ae3d14bc91d69bbd95d4986477d to your computer and use it in GitHub Desktop.
Logical & Assignment operators created by foysalimran - https://repl.it/@foysalimran/Logical-and-Assignment-operators
/*
What is logical operator?
Logical operators usually used to ensure logic between variables and values.
There are 3 types of logical operators.
=>> and / && - It used between 2 operands and if any of them are true then whole thing will true or if any of them are false then whole thing will false. Or if both of statement false full thing will be false.
=> OR / || - It also use between 2 operands and if any of operand true will pass true, if both operand true also will pass true. If only both statements are false then will pass false.
=> NOT / ! - It usually use before a statement and if that is true then it will return false and if it false then it will return false.
*/
// Examples of && / and logical operators
var a = 5;
var b = 10;
var c = 15;
console.log(a > b && b > c); // a/5 is not graterthan b/10 and b/10 is not graterthan c/15 - False
console.log( c > b && b > a); // c/15 is is graterthan b/10 and b/10 is graterthan a/5 - True
console.log( a > b && c > b); // a/5 is not graterthan b/10 and c/15 is graterthan b/10 - False
// Examples of || / or logical operators
console.log(a > b || b > c); // a/5 is not graterthan b/10 and b/10 is not graterthan c/15 - false
console.log( c > b || b > a); // c/15 is is graterthan b/10 and b/10 is graterthan a/5 - True
console.log( a > b || c > b); // a/5 is not graterthan b/10 and c/15 is graterthan b/10 - true
// Examples of ! / not logical operators
console.log(!(a > b || b > c)); // a/5 is not graterthan b/10 and b/10 is not graterthan c/15 - statement is false so returned - true
console.log(!(c > b || b > a)); // c/15 is is graterthan b/10 and b/10 is graterthan a/5 - statement is true so returend - false
console.log(!(a > b || c > b)); // Statement is true so returned - false
/*
What is Assignment operators?
Which operators are using to assigning any value into javascript variables taht's called assignment operators.
There are six types of Assignment opearators.
=> = / Simple assignment operator: It using to assigning a value into variables
=> += / Addition and assignment operator: It addition with it's value and assign with self at the same time.
=> -= / Substraction and assignment operator: Substract with it's value and assign with self at same time.
=> *= / Multiplication and assignment operator: It multiplay with it's value and assign with self at same time.
=> /= / Divition and assignment operator: It devide with it's value and assign with self at same time.
=> %= / Modulas and assignment operator: It's module with it's value and assign with self same time.
*/
// Example of simple assignment operator
var a = 10;
// Example of addition and assignment operator
var a = 10;
a += 10;
console.log(a); // additioned 10 with it's value 10 and pass 20 value
// Example of substraction and assignment operator
var x = 20;
x -= 10;
console.log(b); // substractioned 10 with it's value 20 and pass 10
// Example of multiplication and assignment operator
var y = 5;
y *= 5;
console.log(y); // Multiplied 5 with it's value 5 so value passed 25
// Example of divition and assignment operator
var d = 30;
d /= 5;
console.log(d); // Devided 30 with it's value 5 and passed 6
var m = 10;
m %= 3;
console.log(m); // Moduled 30 with it's value 3 and passed 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment