About javascript
JavaScript is a dynamic, object-oriented, prototype-based, weakly typed language commonly used for scripting in web browsers. Despite the name, it is unrelated to the Java programming language and shares only superficial similarities.
It runs on nearly every OS, and a JavaScript engine is included in almost every mainstream web browser. Developed in 1995 by Brendan Eich at Netscape Communications, it was originally called LiveScript but was renamed to JavaScript due to Netscape's friendly relationship with Sun Microsystems at the time.
Standalone JavaScript engines or interpreters are available as well:
- Mozilla's SpiderMonkey was the first JavaScript engine ever written, currently used in Mozilla Firefox.
- V8, Google's JavaScript interpreter, is used in Google Chrome, node.js (a platform which enables server-side applications to be written in JavaScript) and other projects.
- Windows includes a JavaScript variant in its Windows Script Host jscript.
- Mozilla also offers Rhino, an implementation of JavaScript built in java, typically embedded into Java applications to provide scripting to end users.
- WebKit (except for the Chromium project) implements the JavaScriptCore engine javascriptcore.
The Mozilla Developer Network contains good documentation on JavaScript.
JavaScript is typically used to manipulate the Document Object Model (DOM) and Cascading Style Sheets (CSS) within the browser, offering user interface scripting, animation, automation, client-side validation, and much more.
However, with the recent emergence of frameworks such as Node.js, JavaScript can now be used to write server-side applications.
Nomenclature
People often use the term JavaScript informally. The language and the term originated from Netscape. ECMAScript, JavaScript, and JScript are terms that are easy to confuse.
ECMAScript was developed as a standardization of Netscape's JavaScript and Microsoft's independently-developed JScript. The canonical reference is the ECMA-262 Language Specification. While JavaScript and JScript aim to be compatible with ECMAScript, they also provide additional features (and other deviations) not described in the ECMA specifications. Other implementations of ECMAScript also exist.
The differences today for those who use JavaScript are negligible; people generally do not distinguish the JavaScript and JScript variations from ECMAScript.
When asking a JavaScript question, you should:
- Isolate the problematic code and reproduce it in an online environment such as jsFiddle or JS Bin.
- If a library or framework is used, then tag the question with the appropriate tags: jquery for jQuery,prototypejs for Prototype, mootools for MooTools, and so on. However, if a framework is not used or necessary, do not include these tags.
- Mention which browser the code is having problems on, and what error messages, if any, were thrown by the browser. If the question is browser-specific, use tags firefox, google-chrome, internet-explorer, opera, etc.
- Only tag the question as css or html if you are asking about an issue that concerns the combination of one of those with JavaScript and could only be answered with information specifically regarding either of those subjects.
Learning JavaScript
- Eloquent JavaScript: A Modern Introduction to Programming
- JavaScript Programming Patterns: Collection of Design Patterns for JavaScript
- The MDN JavaScript Guide: A Comprehensive JavaScript Guide at the Mozilla Developer Network
- JavaScript Tutorial: A pure JavaScript book that covers nearly everything.
- W3Schools | JavaScript Tutorial (note that W3Schools can be inaccurate at times, and is not affiliated with the W3C at all - other resources are better. More info here: http://w3fools.com/).
- JavaScript Core Skills from the Web Standards Curriculum
- quirksmode.org | Introduction to Events: A comprehensive description of the various types of event handling. Includes overview of different ways to attach event handlers and points out quirks between different browsers. A must-read if you want to understand event handling.
- W3C Wiki | JavaScript basics, DOM: Programming - the real basics, Creating and modifying HTML,Handling events with JavaScript.
- JavaScript Debugging for Beginners: A good introduction to debugging JavaScript. A must-read!
- Modern JavaScript: Develop and Design: A modern guide to learning JavaScript using practical examples and approaches that should be used today.
Useful Tools
- Firebug Add-on for Firefox
- Developer Tools for IE
- Chrome Developer/Debug Tools for Chrome
Interactive JavaScript learning
- Codecademy | JavaScript: Learn the fundamentals of JavaScript and dynamic programming.
- Udacity | Programming Languages: Key concepts include specifying and processing valid strings, sentences and program structures.
Wisdom from the Stack
- What should every JavaScript programmer know?
- Hidden Features of JavaScript?
- How do JavaScript closures work?
- Return value from function with an Ajax call
- var functionName = function() {} vs function functionName() {}
- How does the (function() {})() construct work and why do people use it?
Useful links
- MDN JavaScript Reference
- W3C DOM Core, HTML, events and CSS compatibility tables from http://www.quirksmode.org
- JSLint Code Quality Tool by Douglas Crockford (and JSHint, a community-driven branch of the original)
- Code minifiers/obfuscators: /packer/, YUI Compressor, Google Closure Compiler, UglifyJS
- Code formatter/deobfuscator: JSBeautifier
- Idioms and Gotchas: Rounding, Date Object, Number Object, Scope Chain, Namespacing
- JavaScript Garden
- comp.lang.javascript FAQ: Very extensive guide on JavaScript quirks created by Usenet'scomp.lang.javascript
- ECMA 262-5 Online: HTML version of ECMA's 262-5 Spec.
- Annotated ES5: Annotated and hyperlinked HTML derivative of the ECMAScript 5 specification.
- Unofficial ES6 draft spec.
- ECMAScript Support Matrix: In-depth feature list for ECMAScript implementations.
- ES6 compatibility table
- Script Tokenization: Comprehensive study of syntax commonality
- JavaScript Weekly: A free, weekly newsletter curated by Peter Cooper
Free JavaScript Programming Books
- Crockford's JavaScript
- Eloquent JavaScript
- Essential JavaScript & jQuery Design Patterns for Beginners
- JavaScript Essentials
- jQuery Fundamentals (starts with JavaScript basics)
- Mozilla Developer Network's JavaScript Guide
- Enterprise Web Development: From Desktop to Mobile
Frequently Asked Questions
Find some answers to some of the more frequently asked questions about JavaScript and related technology below.
Q: I have this JSON structure, how can I access property
A: Access / process (nested) objects, arrays or JSON
x.y.z
?A: Access / process (nested) objects, arrays or JSON
Q: I'm adding events in a for loop but all handlers do the same thing, why?
A: Event handlers inside a Javascript loop - need a closure?
A: Event handlers inside a Javascript loop - need a closure?
Q: I want to compare something against multiple values, is there an easy way to do it?
A: Concise way to compare against multiple values
A: Concise way to compare against multiple values
Q: How can I pass a PHP array to JavaScript?
A: Pass a PHP array to a JavaScript function
A: Pass a PHP array to a JavaScript function
Q: How to set up proper inheritance?
A: Objects don't inherit prototyped functions
A: Objects don't inherit prototyped functions
Q: How do JavaScript closures work?
A: How do JavaScript closures work?
A: How do JavaScript closures work?
Q: Why does
A: setTimeout in a for-loop and pass i as value
setTimeout()
inside a for
loop always use the latest value?A: setTimeout in a for-loop and pass i as value
Q: How to return the response from an AJAX call from a function?
A: How to return the response from an AJAX call?
A: How to return the response from an AJAX call?
Q: Why don't my handlers hooked up in a loop work correctly, and what can I do about it?
A: http://stackoverflow.com/a/16794762/157247
A: http://stackoverflow.com/a/16794762/157247
Q: How can I get query string values?
A: How can I get query string values in JavaScript?
A: How can I get query string values in JavaScript?
Q: What does “use strict” do in JavaScript?
A: What does "use strict" do in JavaScript, and what is the reasoning behind it?
A: What does "use strict" do in JavaScript, and what is the reasoning behind it?
Q: How can I make a redirect page in jQuery/JavaScript?
A: How can I make a redirect page in jQuery/JavaScript?
A: How can I make a redirect page in jQuery/JavaScript?
Q: How to sort an array of objects by a property value?
A: Sorting objects in an array by a field value in JavaScript
A: Sorting objects in an array by a field value in JavaScript
Q: I'm adding elements with JavaScript or jQuery at a later point and adding events but they're not firing, why?
A: You might want event delegation.
A: You might want event delegation.
More information:
- Wikipedia on JavaScript
- MDN - Learn JavaScript
- Creator of JavaScript, Brendan Eich, explains the origin
- JavaScript Tutorial
No comments:
Post a Comment