0

I have a simple question. Imagine I have the following code:

xmlHttp.open("POST", uri, !0), 
xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"), 
xmlHttp.send(JSON.stringify(data))

These are comma separated instructions. What is the biggest difference between using ; instead of ,? Is it just to make sure all instructions are ran even if one of them gives an error or something?

Pedro Silva
  • 263
  • 2
  • 17
  • as far as I know "," separate arguments and ";" ends the line, except for "for loop". Note that creating for example ajax call you are using "," inside the brackets. – Arkadiusz Raszeja May 18 '17 at 13:51
  • yes, it works. I just want to know the difference. `,` isn't only a argument separator, it is also an operator. (like && and ||, but it evaluates both conditions all the time I think) – Pedro Silva May 18 '17 at 13:54
  • It’s the [comma operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator), `,` is not only used for arguments, the things in the `for` loop are _not arguments_. – Sebastian Simon May 18 '17 at 13:57
  • When you're not using the result of each expression for something, there's no practical difference. Expressions grouped by the comma operator will have the result of the last expression – Lennholm May 18 '17 at 14:02
  • This looks very much like the output of a minifier (especially the `!0`). Don't try to learn anything about style from this code. – Bergi May 18 '17 at 14:26
  • it was minified. I am trying to analyse some code. – Pedro Silva May 18 '17 at 16:53

0 Answers0