Frozen global object

If your app uses global object as a config, you should make sure, that this object is truly readonly. So that an attacker can not modify it in dev console. This is how to do it. // example of frozen global object // freeze the config object properties const config = Object.freeze({ httpApi: ‘http://127.0.0.1:20003/v1’, wsApi: …

ES6 generators and async/await

Motivation for this blogpost was my initial ignorance regarding the upcoming ES6 and the generator function. Around christmas 2015 I was looking for a new job, and during one of the assigned test-jobs I had to use generator functions, the .co library, two different databases (one SQL and the other NoSQL)  and node.js. I failed, …

Javascript math. LOL

How much is 77.9 – 70? Usually it is 7.9. Right? But not so in Javascript. In Javascript it is 7.900000000000006. Funny as hell 🙂 You can “fix” this by calling .toFixed() on the result number, but it does not fix the cause. As far as I know you can’t fix it, it is part of …

Convert local time to UTC time in Javascript

This might come in handy. Simple function which converts local time to UTC (Universal Coordinated Time). It accepts single argument of type Date. //converts local time to UTC (Universal Time) function toUTC(/*Date*/date) { return Date.UTC( date.getFullYear() , date.getMonth() , date.getDate() , date.getHours() , date.getMinutes() , date.getSeconds() , date.getMilliseconds() ); } //toUTC()