Last Updated: February 25, 2016
·
1.591K
· jmarizgit

JavaScript Dates - Month weirdness

Another pearl from JavaScript is the odd use of index 0 to express January in dates, try yourself:

var month = new Date(2013, 0, 31)
> Thu Jan 31 2013 00:00:00 GMT-0800 (PST)  

Notice I have used "0" to express "January". Is the same way you use to get the first element in a Array.

var arr = new Array("January", "February", "March", "April")
arr[0]
> "January"

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#javascript
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside