I was perusing the underscore.js library and I found something I haven't come across before:  if (obj.length === +obj.length) { ... }   What is that + operator doing there? For context, here is a direct link to that part of the file....
I found the following code in a JS project:  var a = new Array(); a[0] = 0; for (var b = 0; b < 10; b++) {   a[0] |= b;  }   What does the |= do in the body of the for loop?  The code example is dubious, but has been presented here by V8 for an ex...
I understand the difference in behavior. Date() returns a String representing the current date, and new Date() returns an instance of the Date object whose methods I can call.  But I don't know why. JavaScript is prototyped, so Date is a function...
Edit: This question is out of date as the Polyfill example has been updated. I'm leaving the question here just for reference. Read the correct answer for useful information on bitwise shift operators.    Question:  On line 7 in the Polyfill exam...
I want to get a other property of a associative array when the first one doesn't exist.  JavaScript:  var obj = {"a": "123", "b": "456"}; var test = obj.a || obj.b; console.log(test);   Is it possible to do this in...
I'm trying to understand how the comma operator (,) works in JavaScript, it seems to have a different behaviour when it's not put between parenthesis.   Can someone explain me why ?   Exemple for reference :     var a = 1;  var b = 2;  var c...
Why is the below code actually working?  Code  var firstDate = new Date();  // some time passing here  var secondDate = new Date();  // Difference seems to contain difference in miliseconds.   var difference = secondDate - firstDate;   What I get is,...
I was examining the src of underscore.js and discovered this:  _.isRegExp = function(obj) {     return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false)); };   Why was "!!" used? Should it...
Sorry, I'm a bit of a noob when it comes to javascript. But here is my problem: The following function returns -1 when 0 is inputed  function foo(bar){     return bar || -1; }  foo(0);   is there a nice and elegant way to allow the || operator to...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.