Operators Reference

Next ❯Statements Reference

Used to perform calculations with logical combination of different operators

  • turned_in_notArithmetic Operators
    OperatorsUsedExample
    x=3, y=2
    Result
    +For Addition of number
    For joining multiple string
    For converting a string number into number
    x + y
    "Hel" + "lo"
    + "2.3"
    5
    "Hello"
    2.3
    -For Subtraction
    For converting a string number into negative number
    x - y
    - "2.3"
    1
    -2.3
    *For Multiplicationx * y6
    /For Divisionx / y1.5
    %For Modulus (remainder)x % y1
    **For Exponentiation/Power-Ofx ** y9
    ~~For Floor value~~1.41
    ++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
    OperatorsDescriptionExample
    x=3, y=2
    Result
    &ANDx & y2
    |ORx | y3
    ~NOT~ y3
    ^XORx ^ y1
    <<Zero fill Left Shiftx << 16
    >>Signed Right Shiftx >> 11
    >>>Zero fill Right Shiftx >>> 16


  • turned_in_notComparison Operators
    OperatorsDescriptionExample
    x=3, y=2
    Result
    ==equal tox == yfalse
    ===equal value and equal data typex === yfalse
    !=not equalx != ytrue
    !==not equal value or not equal data typex !== ytrue
    >greater thanx > ytrue
    <less thanx < yfalse
    >=greater than or equal tox >= ytrue
    <=less than or equal tox <= yfalse


  • turned_in_notConditional Operator
    OperatorDescriptionExampleResult
    ? :ternary operator(x > y) ? "Yes" : "No"Yes


  • turned_in_notNullify Operator
    OperatorDescriptionExampleResult
    ??nullify operator
    - To check for !null or !undefined
    null ?? 2
    undefined ?? 2
    4 ?? 2
    2
    2
    4


  • turned_in_notLogical Operators
    OperatorsDescriptionExample
    x=3, y=2
    Result
    &&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
    OperatorsUsedExampleSame As
    =To assign valuex = yx = y
    +=To assign Addition of number or string valuex += yx = x + y
    -=To assign Subtraction valuex -= yx = x - y
    *=To assign Multiplication valuex *= yx = x * y
    /=To assign Division valuex /= yx = x / y
    %=To assign Modulus (remainder) valuex %= yx = x % y
    **=To assign Exponentiation (Power Of) valuex **= yx = x ** y
    &=To assign AND operator valuex &= yx = x & y
    |=To assign OR operator valuex |= yx = x | y
    ^=To assign XOR operator valuex ^= yx = x ^ y
    <<=To assign Zero fill Left Shift valuex <<= yx = x << y
    >>=To assign Signed Right Shift valuex >>= yx = x >> y
    >>>=To assign Zero fill Right Shift valuex >>>= yx = 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
    OperatorsUsed
    ()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
    OperatorsUsedExample
    x={a1:"A", a2:"B"}
    Result
    deleteTo delete a property from an objectdelete x.a1// x deletes 'a1' property now
    inTo check specified value is in an object or nota2 in xtrue
    instanaceofTo check whether an instance is of specified object (Array, Date, Object, String, Number, Boolean, Function, custom object) or notx instanceof Arrayfalse
    typeofTo find the data type of a specified variable, object, function or expression within string, number, boolean, function, undefined, object (object includes array, date), custom objecttypeof xobject
    newTo create an instance of an objectnew Boolean(true)true
    thisTo refer the current object
    javascript:To integrate an expression on a hyper-link, run only when link is clickedjavascript: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( ))
    *base64
    data:text/html,<b>My text</b>My text


  • turned_in_notGlobal Operators
    OperatorsUsed
    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 number
    String()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
    PropertiesUsed
    InfinityTo get a numeric value that represents positive/negative infinity
    NaNTo get constant value as 'NaN'
    undefinedTo check variable has not assigned any value
    prototypeTo add custom properties and methods to an object
    constructorTo get the function that created JavaScript's prototype

  • Statements Reference
❮ Prev Data Types Reference
Next ❯Statements Reference
TryOut Examples"Learn to Explore..!"

TryOut Editor

receipt