background preloader

Javascript

Facebook Twitter

jQuery

What you should know about if you are new to Javascript. What you should know about if you are new to Javascript Unlike server-side or desktop development, where you can use whatever language and whatever framework you want, in client-side development you're pretty much stuck with Javascript. There are some languages that compile to Javascript, and if you really really don't like Javascript, you have some options that you might prefer, like Script#, WebSharper, Dart, CoffeeScript, ClojureScript, Opa, and many others. That said, for better or for worse, Javascript really is the lingua franca of the web.

That means if you want to make a web application, you'll probably end up needing to learn Javascript whether you like it or not. In this article, I will try to go over the most important points about Javascript that you should know about. Javascript's Language Family Javascript's name deceptively suggests that it is based on Java and, like Java, is part of the C language family. Dynamic Typing int x = 5; x = "hello"; var x = 5; x = "hello"; Numbers. Why Javascript is a Joy. I’m probably a bit biased – being a front-end web developer for a few years will do that – but I really enjoy writing Javascript. I’ve recently retreated from pure coding the last few months, but I got an opportunity this past week to jump back into some tasks, and it has reminded me how fun it is to dive into our[1] front-end codebase.

Yes, Javascript can be surprisingly elegant yet completely infuriating, and all on the same line of code; for a long time, it remained the joke of the programming community, the deranged cousin that outuglied even the likes of PHP and Perl. Nowadays, JS is the language in the spotlight, and having its strengths exposed to increasingly more developers make me happy to have stuck with the language, warts and pus and all. Here’s my attempt to collate exactly why I like working with Javascript.

Speed Moreover, JS is really fast to write and test. Simplicity Javascript, for everyday non-gotcha coding, is a pretty lightweight language. Freedom Malleable. Blog @johnkpaul - Javascript - only three “bad” parts. Bouncing Beholder [JS1k entry] My winning JS1K entry---a JavaScript platform game that fits in 1024 bytes. I gave a talk on this at the November Berlin JS user group. Slides here. Though they might be hard to follow without commentary. (See here for my old, space-defense game entry.)

Use the arrow keys to move and jump. Collect as many coins as you can. This is the code (newlines added): I've heard people wax poetic about programming old, limited-memory machines. In typical 21st-century programming, the machine limits one has to deal with are wide and fuzzy. In terms of productivity, this is an awful way of coding. For a start, of course, there are the tiny local tricks that save a few bytes here and there, which adds up to at least a hundred bytes on the whole program. |0 truncates, && or ? Compression algorithms, such as Google's Closure Compiler and UglifyJS, and various eval/replace hacks suggested for the JS1K contest, don't really do much on properly hand-compressed code.

Mechanized Abbreviation The World Physics. Eloquent JavaScript: A Modern Introduction to Programming. JavaScript: The World's Most Misunderstood Programming Language. Douglas Crockford www.crockford.com JavaScript, aka Mocha, aka LiveScript, aka JScript, aka ECMAScript, is one of the world's most popular programming languages. Virtually every personal computer in the world has at least one JavaScript interpreter installed on it and in active use. JavaScript's popularity is due entirely to its role as the scripting language of the WWW. Despite its popularity, few know that JavaScript is a very nice dynamic object-oriented general-purpose programming language. How can this be a secret? Why is this language so misunderstood? The Name The Java- prefix suggests that JavaScript is somehow related to Java, that it is a subset or less capable version of Java.

JavaScript has a syntactic similarity to Java, much as Java has to C. JavaScript was not developed at Sun Microsystems, the home of Java. The -Script suffix suggests that it is not a real programming language, that a scripting language is less than a programming language. Lisp in C's Clothing Typecasting. A re-introduction to JavaScript.

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. JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. JavaScript was first released with Netscape 2 early in 1996. It was originally going to be called LiveScript, but it was renamed in an ill-fated marketing decision that attempted to capitalize on the popularity of Sun Microsystem's Java language — despite the two having very little in common. Several months later, Microsoft released JScript with Internet Explorer 3. Overview And there are some built-in Error types as well.

Numbers. JavaScript: Warts and workarounds. When warts collide: var versus with Lexical block scope in JavaScript is broken, and though the use of with is generally considered poor form, it's a good solution to this problem. In most curly-braced languages, blocks delineate lexical scope. For example, in C or Java: { int i = 13 ; { int i = 42 ; print(i) ; } print(i) ; } this code prints 42 and then 13. But, in JavaScript: { var i = 13 ; { var i = 42 ; console.log(i) ; } console.log(i) ; } this code prints 42 and 42. In JavaScript, only functions introduce a new lexical scope and variable declarations are implicitly hoisted to this level.

For instance: function f () { var i = 13 ; { var i = 42 ; print(i); } print(i) ; } Is equivalent to: function f () { var i ; i = 13 ; { i = 42 ; print(i) ; } print(i) ; } Aside: Hoisting under the hood JavaScript takes hoisting to extremes. The following program -- a lone reference to x -- provokes a reference error: x ; // ReferenceError: x is undefined but the following program is OK because var x gets hoisted: Learning JavaScript in small bites, Part 1. More resources If you like this, you might also enjoy: Part 2 of the JavaScript in small bites series. The Y Combinator in JavaScript. JavaScript: The Good Parts. A JavaScript program from scratch One of the great things about JavaScript programming is that you don't need to buy anything to get started. Once you've created the file, add the tags that indicate the document is an HTML document: [blank.html] Then, add a body tag, which is where you'll place all of the content for a page: [blank-with-body.html] Hello, World!

There are many ways to write the ubiquitous "Hello, World! " [hello-world-no-js.html] <body> Hello, World! Produces: But, of course, we can also use JavaScript to write the content onto the page: [hello-world-with-js.html] <body> <script> document.write("Hello, World! Whenever we want to introduce a script to a part of a page, we just use a <script> tag, and put JavaScript inside of it.

A more annoying way to write a "Hello, World! " [hello-world-alert.html] Variables and values.