JavaScript Passing 2 values when accessing value in javascript array `myArray[1,3]` passing values in java,passing values in url,passing values

I realize that this is improper syntax, but why is JavaScript ignoring the first number and giving a response instead of breaking?

let myArray = [1,2,3,4]

myArray[0,1] // 2
myArray[1,3] // 4
myArray[3,0] // 1 
Answer:1

It's not improper syntax.

That's just the comma operator in action.

From docs:

The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.

For instance, [1,2][1,2], perhaps bizarrely enough, will return undefined.

Why?

The second [ is interpreted by the compiler to be the array subscript operator, because JavaScript's semantics don't allow two arrays to be next to each other.

Thus, the second 1,2 must be an expression that evaluates to an index. 1,2 results in the first operand being evaluated, followed by the second, which is what's returned. So it uses index 2, which of course doesn't exist in that array, and we get undefined.

Answer:2

I have the following code to listen to click events on div elements. HTML: <div id="container"> <div id="1" class="square"></div> <div id="2" class="square"></div&...

I have the following code to listen to click events on div elements. HTML: <div id="container"> <div id="1" class="square"></div> <div id="2" class="square"></div&...

I was searching an issue about a delay in my Pomodoro clock (FreeCodeCamp project) that I discovered when I noticed my test session of one minute should have been done by now. I checked back and it ...

I was searching an issue about a delay in my Pomodoro clock (FreeCodeCamp project) that I discovered when I noticed my test session of one minute should have been done by now. I checked back and it ...

Hya, I have the below setup: App.Component.Ts contents carForm: FormGroup; constructor( private fb: FormBuilder ) { this.carForm= this.fb.group({ name: '', type: '', ...

Hya, I have the below setup: App.Component.Ts contents carForm: FormGroup; constructor( private fb: FormBuilder ) { this.carForm= this.fb.group({ name: '', type: '', ...

I'm using a generated library (LoopBack's Angular SDK) for my model's CRUD operations, and finding it difficult to unit test controllers and services that make use of them. Here's an example where I'...

I'm using a generated library (LoopBack's Angular SDK) for my model's CRUD operations, and finding it difficult to unit test controllers and services that make use of them. Here's an example where I'...

  1. unit test promise
  2. unit test promise reject
  3. unit test promise.all
  4. unit test promise resolve
  5. unit test promise angular
  6. unit test promise angular 2
  7. unit test promise jest
  8. unit test promise mocha
  9. unit test promise jasmine
  10. unit test promise chain
  11. unit test promise catch
  12. unit test promise then
  13. unit test promise javascript
  14. unit test promise node.js
  15. unit test promise java
  16. unit test promise sinon
  17. node js unit test promises
  18. unit test promise example
  19. unit test promise method
  20. angular unit test promise then