Concretely, how do inheritance and the prototype chain work in JavaScript?

I think this explains it pretty well:

From "Christoph" on StackOverflow.
http://stackoverflow.com/questio…

"Every JavaScript object has an internal property called [[Prototype]]. If you look up a property viaobj.propName or obj['propName'] and the object does not have such a property – which can be checked via obj.hasOwnProperty('propName') – the runtime looks up the property in the object referenced by [[Prototype]] instead. If the prototype-object also doesn't have such a property, its prototype is checked in turn, thus walking the original object's prototype-chain until a match is found or its end is reached.

Some JavaScript implementations allow direct access to the [[Prototype]] property, eg via a non-standard property named __proto__. In general, it's only possible to set an object's prototype during object creation: If you create a new object via new Func(), the object's [[Prototype]] property will be set to the object referenced by Func.prototype."

What's the best way to programmatically check for trailing commas in JavaScript?

Closure Compiler (Closure Tools – Google Developers) enforces this rule while minifying, so if you're also looking for a minifier, it can be a good choice.

Otherwise, it's a little bit heavyweight for the task…. JSHint (JSHint, A JavaScript Code Quality Tool) is a pretty sweet fork of JSLint[1] which is designed to be much more configurable than JSLint and runs well from the command line.

[1] Technically, I think JSHint has just been rewritten so that it is no longer dependent on the original JSLint code, but it started off as a fork and is of course still inspired by JSLint (and its inadequacies).

What is a browser independent way to extract the height and width of a rendered image with Javascript?

Is it possible you checked the height and width properties prior to the image being downloaded?

You can either wait for the image to completely load (you can set an onload handler to catch this event), or if you don't want to wait for potentially large images, you can do a setTimeout() and keep checking the image for a height and width property.  I have used this approach quite reliably in all reasonable browsers back to IE6.

Is CoffeeScript a solid foundation upon which to code the JS portions of a RIA web app?

Projects like CoffeeScript, Objective J and GWT are an interesting new trend.

Google, the masters of JavaScript, have their own Google Web Toolkit (GWT) where they code in Java and that gets compiled into JavaScript. They generate separate JS files for each browser to reduce download size and the code can be heavily optimized.

During the Google Wave presentation, they talked about how amazing GWT was, how it allowed them to think differently about what's possible in browsers. Google Wave is a terrible application, with constant script timeout errors and overall poor performance. That's not good, but the newest version of Google Documents might be coded with GWT, as well as other apps that are released and in wide use.

Google's Quake 2 Demo was ported from Java with the help of GWT.

These languages on top of JavaScript come with new problems, but CoffeeScript should have the least of them. If a company like Google takes these risks, other developers should too.

If there is something serious to be afraid of, it's a lack of community around CoffeeScript, not enough projects using it, few libraries catered to it. So if we don't use it, we'll lose it.

Is JavaScript the most popular programming language in the world?

At this moment the web is certainly the popular and most widely used platform for application development.The rendering engine used in browser is leveraged to build cross platform applications like hybrid apps and progressive web apps. As you perhaps know JavaScript was born for the browser. If it is said that "C/C++ is closer to the machine" then it can be said that "JavaScript is closer to the browser".

Right now if you are building anything for the web or more precisely anything that is rendered with the browser's engine, you pretty much need to have JavaScript in your technology stack. (Try to recall the last time you had to use a website/ web application that does not use JavaScript !! )

Having said all these, let's take a look at Stack Overflow Developer Survey 2016 Results

(I hope you will take time to check out the whole survey)

Some key results that tops this survey :

  • Developer Occupations : Full Stack Web Developer
  • Most Popular Technologies per Dev Type
    • Full-Stack : JavaScript
    • Front-End: JavaScript
    • Back-End: JavaScript (Not my personal opinion, it's the survey results)
    • Mobile: JavaScript (6th)
    • Math & Data: JavaScript (5th)
    • Students: JavaScript (2nd)
  • Most Popular Technologies
    • 2016 : JavaScript
    • 2015 : JavaScript
    • 2014 : JavaScript
    • 2013 : JavaScript

(Source: Stack Overflow Developer Survey 2016 Results)

phew , that's a long list !!

Now, let's check out JavaScript in the open-source world.

It will be pretty obvious once you take a look at this question here : What are the most popular GitHub repositories of all time?

Or, the most starred repo at GitHub : Build software better, together

Or, the repositories with most forks on GitHub: Build software better, together

Before I finish, let me just remind you (as well as myself) that Stack Overflow and GitHub are just two metrics focused here to describe the popularity of JavaScript. And it is certainly expected that these metrics are not perfect and if we had used other metrics we might come up with different conclusions.

What is the most elegant and concise way to cast a value to a bool in JavaScript?

An important "method" that wasn't previously mentioned is that JavaScript does this implicitly wherever it can by evaluating expressions into expression references and then coercing the expression reference to a boolean for conditional evaluation. The easiest way to illustrate this is with a code example:


var foo = "bar";

if ( foo ) {
  // any code here will execute because the condition evaluated to true.
}


Here is the production from ECMA-262, Edition 5:

The production IfStatement : if ( Expression ) Statement else Statement is evaluated as follows:

  1. Let exprRef be the result of evaluating Expression.
  2. If ToBoolean(GetValue(exprRef)) is true, then
    1. Return the result of evaluating the first Statement.
  3. Else,
    1. Return the result of evaluating the second Statement.

The production IfStatement : if ( Expression ) Statement is evaluated as follows:

  1. Let exprRef be the result of evaluating Expression.
  2. If ToBoolean(GetValue(exprRef)) is false, return (normal, empty, empty).
  3. Return the result of evaluating Statement.

The important parts to note here are steps 1 & 2 from either production.