background preloader

Learning

Facebook Twitter

Closures

Sneaky Abstractions: Scope in JavaScript. Dojo's broken module naming convention. JavaScript Kit Advanced JavaScript Tutorials. A re-introduction to JavaScript - MDN Docs. Why a re-introduction? Because JavaScript is notorious for being the world's most misunderstood programming language. It is often derided as being a toy, but beneath its layer of deceptive simplicity, powerful language features await. JavaScript is now used by an incredible number of high-profile applications, showing that deeper knowledge of this technology is an important skill for any web or mobile developer. It's useful to start with an overview of the language's history. Several months later, Microsoft released JScript with Internet Explorer 3.

Because it is more familiar, we will refer to ECMAScript as "JavaScript" from this point on. Unlike most programming languages, the JavaScript language has no concept of input or output. Overview JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. Let's start off by looking at the building blocks of any language: the types. And there are some built-in Error types as well. Numbers. JavaScript Garden. Function Declarations and Expressions Functions in JavaScript are first class objects. That means they can be passed around like any other value. One common use of this feature is to pass an anonymous function as a callback to another, possibly an asynchronous function.

The function Declaration function foo() {} The above function gets hoisted before the execution of the program starts; thus, it is available everywhere in the scope it was defined, even if called before the actual definition in the source. foo(); // Works because foo was created before this code runsfunction foo() {} The function Expression var foo = function() {}; This example assigns the unnamed and anonymous function to the variable foo. foo; // 'undefined'foo(); // this raises a TypeErrorvar foo = function() {}; Due to the fact that var is a declaration that hoists the variable name foo before the actual execution of the code starts, foo is already declared when the script gets executed.

Named Function Expression How this Works. jMar's Blog: Understanding Loose Typing in JavaScript. For many front end developers, JavaScript was their first taste of a scripting and/or interpretive language. To these developers, the concept and implications of loosely typed variables may be second nature. However, the explosive growth in the demand for Web 2.0-ish applications has resulted in a growing number of back end developers that have had to dip their feet into pool of client side technologies. Many of these developers are coming from a background in strongly typed languages, such as C# and Java, and are unfamiliar with both the freedom and the potential pitfalls involved in working with loosely typed variables.

Since the concept of loose typing is so fundamental to scripting in JavaScript, an understanding of it is essential. This article is a top level discussion of loose typing in JavaScript. Since there may be subtle differences in loose typing from language to language, let me constrain this discussion to the context of JavaScript. What is Loose Typing? Type Coercion.