I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.  The previous developer uses two ways of declaring functions and I can&#...
Other than the obvious fact that the first form could use a variable and not just a string literal, is there any reason to use one over the other, and if so under which cases?  In code:  // Given: var foo = {'bar': 'baz'};  // Then...
I'm pulling items out of the DOM with jQuery and want to set a property on an object using the id of the DOM element.   Example  const obj = {}  jQuery(itemsFromDom).each(function() {   const element = jQuery(this)   const name = element.attr(&...
Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error:     Problem at line 1 character 1: Missing "use strict" statement.   Doing some searching, I realized that some people add "use...
I was recently comparing the current version of json2.js with the version I had in my project and noticed a difference in how the function expression was created and self executed.  The code used to wrap an anonymous function in parenthesis and the...
Summary  Can you explain the reasoning behind the syntax for encapsulated anonymous functions in JavaScript? Why does this work: (function(){})(); but this doesn't: function(){}();?    What I know  In JavaScript, one creates a named function li...
Have you ever taken a look under the hood at the jQuery 1.4 source code and noticed how it's encapsulated in the following way:  (function( window, undefined ) {    //All the JQuery code here    ...  })(window);   I've read an article on Ja...
One of the tips for jslint tool is:     ++ and --   The ++ (increment) and -- (decrement)    operators have been known to contribute to bad code by   encouraging excessive trickiness. They   are second only to faulty architecture   in enabling to v...
If I try to write  3.toFixed(5)   there is a syntax error. Using double dots, putting in a space, putting the three in parentheses or using bracket notation allows it to work properly.  3..toFixed(5) 3 .toFixed(5) (3).toFixed(5) 3["toFixed"...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.