Results 1 to 2 of 2

Thread: Comma Operator

  1. #1
    Senior Member
    Join Date
    Jun 2015
    Thanked 0 Times in 0 Posts

    Comma Operator

    operand1, operand2, operand3, ...

    The comma operator is rarely used. You can use it to force the evaluation of a set of expressions. The comma operator is also called a parameter delimiter because it does just that. You probably recall that we used the comma operator in functions when we wanted a function to accept multiple arguments.

    In this example, the comma operator delimits the methodís arguments:

    var beerNum = 99
    document.write(beerNum, " bottles of beer on the wall")
    Here is another example

    var a = (b = "Hello", alert("Hi"), "Howdy")
    The comma operator forces the evaluation of all expressions in the statement. Only the last expression is returned, so the value of a would be "Howdy". This statement is equivalent to the following set of statements:

    b = "Hello"
    var a = "Howdy"

  2. #2
    Junior Member
    Join Date
    Dec 2018
    Thanked 0 Times in 0 Posts
    In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).

    The use of the comma token as an operator is distinct from its use in function calls and definitions, variable declarations, enum declarations, and similar constructs, where it acts as a separator.

Similar Threads

  1. Explain the scope resolution operator?
    By beingchinmay in forum Web Programming
    Replies: 0
    Last Post: 02-15-2016, 10:23 AM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts