Monday, March 17, 2014

The <script> element

The unobtrusive javaScript programming paradigm

Unobtrusive JavaScript is an approach to web programming that supports separation of behaviour (JavaScript code), structure (HTML code) and presentation (CSS code).
According to this programming paradigm, to accomplish separation is best to write all your JavaScript in an external file and embed it in HTML document using a <script> element with src attribute.

The <script> element is synchronous by default

Let's examin how the <script> element allow you to insert javascript in a HTML document.
<script src="scripts/javascript_app.js"> </script> <!--synchronous script-->

When JavaScript engines encounters a <script> element, they stop parsing HTML to download and interpreter the JS file, then they resume parsing and rendering HTML.

The <script> element has two important attribute: HTML 4.1 defines the async attribute and HTML5 introduces the defer attribute. These two attributes cause scripts to be executed differently, in browsers supporting them.

JavaScript Versions

JavaScript Birth

JavaScript was created at Netscape in 1998, and the name JavaScript is a trademark of Oracle. Netscape submitted the language for standardization to ECMA (the European Computer Manufacturer’s Association) and, because of trademark issues, the standardized version of the language was given the name ECMAScript.

Browser Vendors' Names for JavaScript

Mozilla calls its ECMAScript implementation JavaScript and Microsoft JScript.

JavaScript Versions

By 2008, all major web browsers were compliant with the standard ECMAScript version 3.
In December 2009, ECMAScript version 5 was defined and the first browsers to implement it were Internet Explorer 9 and Firefox 4.
The only versions that are relevant are ECMAScript version 3 and 5.

http://caniuse.com/#search=ecmascript

Saturday, March 8, 2014

JavaScript Type Conversions

1. Implicit Types Conversions

JavaScript is flexible about the types of values it needs. When JavaScript expects a boolean value, you may supply a value of any type, and JavaScript will convert it automatically as it needs. If JavaScript wants a string, it will convert whatever value you give it to a string. If JavaScript wants a number, it will try to convert the value you give it to a number.

Truthy values and falsy values

The following six values convert to false and are also called falsy values:
undefined, null, 0, -0, NaN, ""
All other values (comprised any object and any array) convert to true and work like true.