Create an empty object in JavaScript with {} or new Object()?

Objects There is no benefit to using new Object(); – whereas {}; can make your code more compact, and more readable. For defining empty objects they’re technically the same. The {} syntax is shorter, neater (less Java-ish), and allows you to instantly populate the object inline – like so: Arrays For arrays, there’s similarly almost no benefit to ever using new Array(); over []; – … Read more

Cannot read property ‘forEach’ of undefined

There is no semicolon at the end of the first line. So the two lines run together, and it is interpreted as setting the value of funcs to The expression 1, 2 becomes just 2 (comma operator), so you’re trying to access index 2 of an empty array: And undefined has no forEach method. To fix this, always make sure you put a semicolon at … Read more

Getting the client’s time zone (and offset) in JavaScript

Using an offset to calculate Timezone is a wrong approach, and you will always encounter problems. Time zones and daylight saving rules may change on several occasions during a year, and It’s difficult to keep up with changes. To get the system’s IANA timezone in JavaScript, you should use  Run code snippetExpand snippet As of September 2019, … Read more