Operators Reference
Next ❯Statements Reference
- turned_in_notArithmetic Operators
Operators Used Example
x=3, y=2Result + For Addition of number
For joining multiple string
For converting a string number into numberx + y
"Hel" + "lo"
+ "2.3"5
"Hello"
2.3- For Subtraction
For converting a string number into negative numberx - y
- "2.3"1
-2.3* For Multiplication x * y 6 / For Division x / y 1.5 % For Modulus (remainder) x % y 1 ** For Exponentiation/Power-Of x ** y 9 ~~ For Floor value ~~1.4 1 ++ For Increment
Prefix ++i
Postfix i++
x = ++y
x = y++
x = 3 , y = 3
x = 2 , y = 3-- For Decrement
Prefix --i
Postfix i--
x = --y
x = y--
x = 1 , y = 1
x = 2 , y = 1
- turned_in_notBitwise Operators
Operators Description Example
x=3, y=2Result & AND x & y 2 | OR x | y 3 ~ NOT ~ y 3 ^ XOR x ^ y 1 << Zero fill Left Shift x << 1 6 >> Signed Right Shift x >> 1 1 >>> Zero fill Right Shift x >>> 1 6
- turned_in_notComparison Operators
Operators Description Example
x=3, y=2Result == equal to x == y false === equal value and equal data type x === y false != not equal x != y true !== not equal value or not equal data type x !== y true > greater than x > y true < less than x < y false >= greater than or equal to x >= y true <= less than or equal to x <= y false
- turned_in_notConditional Operator
Operator Description Example Result ? : ternary operator (x > y) ? "Yes" : "No" Yes
- turned_in_notNullify Operator
Operator Description Example Result ?? nullify operator
- To check for !null or !undefinednull ?? 2
undefined ?? 2
4 ?? 22
2
4
- turned_in_notLogical Operators
Operators Description Example
x=3, y=2Result && and - true if all conditions are true (x > y && x==y) false || or - true if any condition is true (x > y || x==y) true ! not - the opposite of actual result ! (x > y) false
- turned_in_notAssignment Operators
Operators Used Example Same As = To assign value x = y x = y += To assign Addition of number or string value x += y x = x + y -= To assign Subtraction value x -= y x = x - y *= To assign Multiplication value x *= y x = x * y /= To assign Division value x /= y x = x / y %= To assign Modulus (remainder) value x %= y x = x % y **= To assign Exponentiation (Power Of) value x **= y x = x ** y &= To assign AND operator value x &= y x = x & y |= To assign OR operator value x |= y x = x | y ^= To assign XOR operator value x ^= y x = x ^ y <<= To assign Zero fill Left Shift value x <<= y x = x << y >>= To assign Signed Right Shift value x >>= y x = x >> y >>>= To assign Zero fill Right Shift value x >>>= y x = x >>> y []=[] Destructuring array
To assign similar array structure variables[a,b] = [1,2] a = arr[0],
b = arr[1]{}={} Destructuring object
To assign similar object structure variables{a,b} = {a:1,b:2} a = obj.a,
b = obj.b
- turned_in_notExpression Operators
Operators Used () To evaluate grouped expression
To create a function()=> To create an arrow function ()() To auto run a function
To create a functional object constructor, (comma) To create multiple expressions in single statement and returns the result of the last expression
To separate elements of array or object: (colon) To define a property value as used in object, switch-case, lebels ; (semicolon) To terminate or end an statement . (dot) To access property or method of an object '' (single quote) To create a string "" (double quote) To create a string `` (back-tick) To create single statement string, integrating JavaScript code using $ into it ${} To add javascript codes inside ``(back-tick) operator {} To create an object [] To create an array
To access values in an array
To access property of an object/ / To create a Regular expression // To create a single-line comment /* */ To create a multi-line comment ... (triple dot)
To create a rest parameter inside a function
// Spread syntax allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.
To create new copy of any array or object
- turned_in_notExtra Operators
Operators Used Example
x={a1:"A", a2:"B"}Result delete To delete a property from an object delete x.a1 // x deletes 'a1' property now in To check specified value is in an object or not a2 in x true instanaceof To check whether an instance is of specified object (Array, Date, Object, String, Number, Boolean, Function, custom object) or not x instanceof Array false typeof To find the data type of a specified variable, object, function or expression within string, number, boolean, function, undefined, object (object includes array, date), custom object typeof x object new To create an instance of an object new Boolean(true) true this To refer the current object javascript: To integrate an expression on a hyper-link, run only when link is clicked javascript:void(console.log(2+3)) 5 //print on console data: To create a data of specific type, to be used as inline data for a source (src, href, srcdoc Attributes, url( ))
*base64data:text/html,<b>My text</b> My text
- turned_in_notGlobal Operators
Operators Used Boolean() To convert a defined variable value (!null, !undefined) to a boolean decodeURI() To decode a URI decodeURIComponent() To decode a URI component encodeURI() To encode a URI encodeURIComponent() To encode a URI component eval() To evaluate a string and executes it as if it was script code isFinite() To convert into number then checks whether a value is a finite, legal number isNaN() To convert into number then checks whether a value is an Not-a-Number Number() To convert a defined variable value (!null, !undefined) to a number parseFloat() To parse a string and returns a floating point number parseInt() To parse a string and returns an integer
To convert digital form (like binary, octal, hex) into decimal numberString() To convert a defined variable value (!null, !undefined) to a string toString() To convert a defined variable value (!null, !undefined) to a string
To convert any number into its digital form (like binary, octal, hex)uneval() * To create script code as a string valueOf() To get the primitive value of an object (Array, Date, Object, String, Number, Boolean, Function, custom object) void() To run any expression and returns undefined, similar to eval( ) but don't run string as script code
- turned_in_notGlobal Properties
Properties Used Infinity To get a numeric value that represents positive/negative infinity NaN To get constant value as 'NaN' undefined To check variable has not assigned any value prototype To add custom properties and methods to an object constructor To get the function that created JavaScript's prototype
❮ Prev Data Types Reference
Next ❯Statements Reference