Are there any performance consequences of having lots of HTML elements that are removed from the document?

No. I've verified with Chrome 12 and the profiler, there are no memory leaks after running your snippet. It should be said though that jQuery has it's own garbage collector, you might not get the same results adding your elements manually to the DOM.

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.

Do JSON lists preserve ordering?

Yes. JavaScript arrays are maintained in-order, and JSON encoders/decoders maintain the order as well. "An array is an ordered collection of values."[1]

Any confusion probably arises from this: JavaScript arrays can be accessed like an object (with keys "0", "1", "2", …) and those keys are not necessarily ordered, for example, when using for(k in object) {…}. This does not impact the ordering of your array, though.

[1] http://www.json.org/

Is it possible to pass variables into an onReadyStateChange function for and XMLHTTP object?

The reason that wouldn't work is because the value you set for xmlhttp.onreadystatechange has to be a function. If you have function() or function(arg1, arg2), it wouldn't work because the value would be the value returned by the execution of the function.

Try xmlhttp.onreadystatechange = function (){ function(arg1, arg2);}

What are good alternatives to Fancybox?

I would recommend using color box found here: http://colorpowered.com/colorbox/ Thickbox was essentially a jQuery plugin proof of concept by Paul Irish that he has not maintained in years. Another option is to use the jQuery UI dialog box. jQuery UI is heavier but if you need any of the their other widgets like a datepicker or accordion might as well bite the bullet and go that direction.

In HTML5, are you supposed to wrap inline script blocks in a CDATA section?

The short answer is no, you do not need to include this.

You would infact not need to include the CDATA wrapper in either of your examples.  The issue arises because XML has to be "well formed", so that affects JavaScript in that all less than "<", greater than ">", and ampersand "&" characters have to be escaped using entity encodings.  None of the browsers will parse a text/html document as XML so actually encoding these characters using their entity encodings do not get unescaped as part of the parsing cycle, so the only option is to use the literal characters.  But this is invalid XML.  To get around this some people recommend using a CDATA section, which will allow any characters within to not be escaped using XML's escaping rules.  None of the browsers will do anything with this and it is only useful if there is a chance that you'll be passing your markup through an XML parser at some point.

HTML5 is a lot more liberal, the spec allows any combination of characters inside of a pair of script tags, but makes special exceptions for HTML comments "<!–", and "–>" and also the script tag pairs themselves, "<script>", and "</script>".  So long as you're careful when including any of these substrings inside of a pair of script tags you do not need to worry about including comments/escape sequences within your script tags!