Are there constants in JavaScript?

Is there a way to use constants in JavaScript? If not, what's the common practice for specifying variables that are used as constants?

How to trigger a file download when clicking an HTML button or JavaScript

This is crazy but I don't know how to do this, and because of how common the words are, it's hard to find what I need on search engines. I'm thinking this should be an easy one to answer. I want a...

When to use Vanilla JavaScript vs. jQuery?

I have noticed while monitoring/attempting to answer common jQuery questions, that there are certain practices using javascript, instead of jQuery, that actually enable you to write less and do...

Usage of the backtick character (`) in JavaScript

In JavaScript, a backtick<sup>&dagger;</sup> seems to work the same as a single quote. For instance, I can use a backtick to define a string like this: var s = `abc`; Is there a way in which the...

Fixed page header overlaps in-page anchors

If I have a non-scrolling header in an HTML page, fixed to the top, having a defined height: Is there a way to use the URL anchor (the #fragment part) to have the browser scroll to a certain point...

Javascript Common Tasks Form Library

I'm interesting if somebody knows a library with common tasks when manipulating forms, I need some advanced tasks like conditional selectors that display/hide other fields, cloning fields, reset...

What is the standard naming convention for html/css ids and classes?

Does it depend on the platform you are using, or is there a common convention that most developers suggest/follow? There are several options: id=&quot;someIdentifier&quot;&#39; - looks pretty...

Do common JavaScript implementations use string interning?

Do common JavaScript engines, such as V8 and WebKit's JavaScriptCore, use string interning for JavaScript strings? Or do they actually keep multiple instances of identical strings in memory?

JavaScript common method to multiple existing constructors

I am rather new to Javascript's way of dealing with constructors,methods and prototypes. I want to create two constructors that have many different custom methods, but also have some methods in...

Javascript common DRY programming idioms

var veryLongObjectName = {}; // ... if (!veryLongObjectName[&quot;verylongpropertyName&quot;]) veryLongObjectName[&quot;verylongpropertyName&quot;] = 0; if...

JavaScript - Common Function to check Undefiend and Null

I have a number of variables in my script, each of which could contain a value, undefined or null. I've noticed alot of repetative code checking for undefined and nulls, can a common function be...

Handling common JavaScript files in Visual Studio 2010

We're beginning work on a couple of fully JavaScript-dependent web apps (our previous apps have been ASP.NET MVC, with JavaScript 'goodness' sprinkled over-the-top). We have a few files that will...

Convert object array to hash map, indexed by an attribute value of the Object

Use Case The use case is to convert an array of objects into a hash map based on string or function provided to evaluate and use as the key in the hash map and value as an object itself. A common...

javascript: common commands in switch statement

I have a situation using switch to filter out say a big array. It goes like var myArray = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;]; $.each( myArray, function (ind, elem) { switch...

Pass angular value to common JavaScript

I am trying to pass a value from angular scope to common JavaScript. The JavaScript is like this &lt;script type=&quot;text/javascript&quot;&gt; var epaycode = null; var epaybuysum =...

Why is it common to put CSRF prevention tokens in cookies?

I'm trying to understand the whole issue with CSRF and appropriate ways to prevent it. (Resources I've read, understand, and agree with: OWASP CSRF Prevention CHeat Sheet,...

How can I override the OnBeforeUnload dialog and replace it with my own?

I need to warn users about unsaved changes before they leave a page (a pretty common problem). window.onbeforeunload = handler This works but it raises a default dialog with an irritating...

Longest Common Prefix in Javascript

I am trying to solve the Leet Code challenge 14. Longest Common Prefix: > Write a function to find the longest common prefix string amongst an array of strings. > > If there is no common prefix,...

Common Regular Expression for java and Javascript

I am looking to have a common framework to write some syntactic validation rules in regular expressions so that I can use them in both frontend and backend. I am using javascript for the front end...

iterate through a common javascript collection?

So I have a common javascript collection, in this form: function populateCollection(){ var Collection = new Array(); Collection[&#39;A&#39;] = &#39;Awesome&#39;; ...

Common JavaScript files across multiple Solutions

One of the systems I currently work on has a number of solutions, each with a single MVC UI project (see below for an example layout). Most of the UI projects share a fair amount of JavaScript and...

Managing Common Client Side code (javascript/css)

We have multiple J2EE web applications on our platform. Many client side code (javascript/css) are common for those applications. As of now we are maintaining separate code for each applications...

Managing common javascript dependencies in Symfony 2

I would like to know what is the standard best practice for dealing with common JavaScript (and even CSS) dependencies across several Symfony 2 bundles. According to the Book on the official...

Common words with Javascript

I want to get the common words from a string. I found out this method: http://jsbin.com/nufimudivu/1/edit for(var i = 0; i &lt; words.length; i++) { wordCounts[&quot;_&quot; + words[i]] =...

Creating common class in javascript

I have one html page with some div and table inside div. Getting data by using XHTMLREQUEST. How can I make this to wrapper class so I can use it whenever I want in project with some id. I can...

Common code between javascript and controllers in rails

I have a set of colors which are accessed by both my controllers and javascript files colors = [&quot;#66c2a5&quot;, &quot;#abdda4&quot;, &quot;#abdda4&quot;, &quot;#fee08b&quot;,...

IE8: Common performance glitches with Javascript?

IE8 and Javascript in general: what are the common problems causing performance glitches on IE8? Does anybody know of a collection of issues and things to avoid when developing scripts for IE8? It...

Greater Common Divisor/ Least Common Divisor for JavaScript

I'm trying to figure out some issues for calculating the Least Common Multiple (LCM). In order to calculate GCD (for two or three numbers) I'm using two...

Find the common members of two Javascript objects

What is the easiest way to find the common members in two Javascript objects? This question is not about equality. I don't care about the values of each member, just that they exist in both...

Merge two javascript objects adding values of common properties

I have two or more javascript objects. I want to merge them adding values of common properties and then sort them in descending order of values. e.g. var a = {en : 5,fr: 3,in: 9} var b = {en:...