Why is ~null === -1?

A questions that stumped me on this JavaScript test was that ~null evaluates to -1. Why does ~null evaluate to -1?

Single quotes within json value

This question already has an answer here: How can I accommodate a string with both single and double quotes inside of it in Javascript 4 answers How to escape special characters in building a JSON string? 9 answers

JavaScript Loop and wait for function

I have a simple single-dimension array, let’s say: fruits = [“apples”,”bananas”,”oranges”,”peaches”,”plums”]; I can loop through with with $.each() function: $.each(fruits, function(index, fruit) { showFruit(fruit); }); but I’m calling another function which I need to finish before moving on to the next item. So, if I have a function like this: function showFruit(fruit){ $.getScript(‘some/script.js’,function(){ // Do […]

NodeJS – how to break a function?

Recently had a similar question, but still can’t get it. I have to validate registration page before adding new user. app.post(‘/signup’, function(req, res) { //checking if first name is filled if (req.body.first_name = “” || req.body.first_name = null || req.body.first_name = undefined) { res.render(‘signup’, { “title”: “Ttitle”, “menu”: “signup”, user: req.user, “error” : “empty_first_name” }); […]

Ember.js size of DS.ManyArray

How to do it? Simple JS .length returns undefined.

Tooltipster does not work in a generated content

I have installed Tooltipster on my website, but it does not work for content added dynamically. You can see it in the “SORT GAMES BY YOUR CHOICE (NEWEST GAMES BY DEFAULT)” box, when I select sort by “newest first”, “most popular,” etc… when the content is generated, Tooltipster does not see that content. Somehow I […]

Modifying an ISO Date in Javascript

I’m creating several ISO dates in a Javascript program with the following command: var isodate = new Date().toISOString() which returns dates in the format of “2014-05-15T16:55:56.730Z”. I need to subtract 5 hours from each of these dates. The above date would then be formatted as “2014-05-15T11:55:56.730Z” I know this is hacky but would very much […]

Form Control Workaround – Chrome Error

I am trying to get around the: An invalid form control with name=’dob_mm’ is not focusable. Error that comes in Chrome. Yes, we have a bunch of fields that are required, and yes, these fields are hidden. The form is broken out into tabs, which only one show at a time. Is there some type […]

Node.js encrypts large file using AES

I try to use following code to encrypt a file of 1 GB. But Node.js abort with “FATAL ERROR: JS Allocation failed – process out of memory”. How can I deal with it? var fs = require(‘fs’); var crypto = require(‘crypto’); var key = “14189dc35ae35e75ff31d7502e245cd9bc7803838fbfd5c773cdcd79b8a28bbd”; var cipher = crypto.createCipher(‘aes-256-cbc’, key); var file_cipher = “”; var […]

Very Basic setAttribute on JavaScript

I’m very beginner in JavaScript and I can’t understand why in this simple code, appears in the console color.setAttribute is not a function <style> .red {color:red;} .blue { color: blue;} </style> </head> <body> <p class=”red”>Hello World</p> <script> var color = document.getElementsByClassName(“red”); color.setAttribute(“class”,”blue”); </script>