Introduction To JavaScript
Introduction To JavaScript
Objectives
Learn about the JavaScript language, its history, uses, and versions Explore some of the tools available to develop and debug JavaScript code See the anatomy of JavaScript, its core structural features
Agenda
The JavaScript Language Developing and Debugging JavaScript The Anatomy of JavaScript
Browsers live on because of JavaScript Most used programming language in the world
Closest thing we have to universal language
For the most part, you can ignore the bad parts
Rise to Fame
Long denigrated as a flawed, toy language
Uncertain whether it would survive Java was expected to replace it
ECMAScript Releases
Version 1 2 3 Release Date June 1997 June 1998 December 1999 -Major Changes Initial release. Primarily editorial changes to keep the specification aligned with the ISO/IEC 16262 international standard for ECMAScript. Added support for regular expressions, improved string handling, new control statements, exception handling, and various numeric output formatting, and more. Abandoned due to political differences and technical difficulties with the complexity of the language. Some features developed made it into version 5, others were deferred for future versions. Added Strict mode, clarified ambiguities, and implemented accommodations for real-world uses of implementations. Added getters and setters, support for JSON, and reflection on object properties. Released to align with the third edition of the international standard ISO/IEC 16262:2011.
5.1
State of ECMAScript
All modern browsers now use ECMAScript 3 ECMAScript 5 slowly making its way into browsers
Default Strict
Language Versions
Many versions in many places
JavaScript Version 1.0 1.1 1.2 1.3 1.5 1.6 1.7 1.8 1.8.1 1.8.2 1.8.5 Version Released March 1996 August 1996 June 1997 October 1998 November 2000 November 2005 October 2006 June 2008 June 2009 January 2010 March 2011 Equivalent to Netscape Navigator 2.0 3.0 4.0-4.05 4.06-4.7x 6.0 Mozilla Internet Firefox Explorer 3.0 Google Chrome
4.0 5.5-8.0
1.010.0.666
ECMAScript 5
9, 10
13.0+
Strategies
Write standards-compliant code Check the environment
Options
Degrade gracefully Progressive enhancement
Elements Panel
Displays the Web page that the browser renders
Explore its HTML, CSS styles, and DOM objects Can make changes
Powerful tools for fine-tuning appearance and solving layout and content problems
Resources Panel
Lists all of the resources used by the page
HTML page itself CSS stylesheet files JavaScript and other code files Cookies and various types of storage Caches
Network Panel
Information about the resources the browser downloads for a page
Resources Panel: content and characteristics of the page resources Network panel: focused on network resources needed to retrieve the page resources
Scripts Panel
Powerful, in-browser script debugger Rivals features of Web development environments
Timeline Panel
Useful to diagnose and fix performance problems in JavaScript code
As well as other resources used by the page
Profiles Panel
Profile both CPU and heap memory Like Timeline, have to explicitly start and stop recording Analyze events in the panel
Audits Panel
Provides network utilization and performance information about a Web page
Based either on reloading or loaded state
Console Panel
Scripts and Console panels together provide powerful tools for JavaScript code Use Console to directly enter and execute JavaScript code Can write to the Console from code
JSLint
Invaluable tool while learning and even after you become an expert Static code analysis tool
Insight into quality of your code Written by Douglas Crockford Available online and in command line versions
Prevent older browsers from treating as page content Such browsers are nearly extinct now, so no need to do this anymore
Copyright by Application Developers Training Company www.learnnowonline.com
Case Sensitivity
JavaScript is case-sensitive All of these are unique identifiers
dateofbirth DateOfBirth dateOfBIRTH dAtEoFbIrTh DATEOFBIRTH
Identifiers
Name for anything you create in code
Variables, arrays, functions, labels, and objects
Valid identifiers
a, aaa, $birth, _birth, _$birth67, app$dev, x123$, birth_date
Invalid identifiers
23birth, *birth, Birth-date
Copyright by Application Developers Training Company www.learnnowonline.com
Reserved Words
Keywords of the language Depends on version of JavaScript youre using To be safe, avoid all reserved words from all versions
abstract arguments boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield
Literals
Fixed value that appears in code
As opposed to a variable whose value can change
Semicolons
JavaScript uses semicolons (;) as statement terminator
Lets you break long statements on multiple lines Interpreter combines everything at runtime
Whitespace
In JavaScript, extra whitespace is irrelevant Need spaces between identifiers and keywords Line breaks are sometimes significant, but not often Language ignores any extra leading indentations, line breaks, tabs, and spaces
Comments
Commenting code is a universal best practice
Provides some level of documentation Aids in maintenance
Browser needs access to code, so you can explore it for any site
Use your developer tools to explore
Learn More!
This is an excerpt from a larger course which you can access at: http://learnnowonline.com/