Operators
Arithmetic Operators
+ - * / %
let a = 5;
let b = a + 1; //6
let c = a - 1; //4
let d = a * 2; //10
let e = a / 2; // ⭐️ 2 not 2.5
let f = a % 2; //1
let g = 5.0 / 2.0; //2.5💡 Also + is used for array and string concatenation
Comparison Operators
== != < > <= >=
let a = 1;
let b = 2;
let c = a == b; //false
let d = a != b; //true
let e = a < b; //true
let f = a > b; //false
let g = a <= a; //true
let h = a >= a; //true
// 🔎
let i = true > false; //true
let j = 'a' > 'A'; //trueLogical Operators
! && ||
🔎 On integer types, ! inverts the individual bits in the two’s complement representation of the value.
Bitwise Operators
& | ^ << >>
Assignment and Compound Assignment Operators
The = operator is used to assign a name to a value or a function. Compound Assignment Operators are created by composing one of + - * / % & | ^ << >> operators with = operator.
Type Casting Operator
as
Borrowing and Dereference Operators
& &mut *
The & or &mut operators are used for borrowing and * operator for Dereferencing.
🔎 For more information, refer Ownership, Borrowing & Lifetimes sections.
Last updated