SlideShare a Scribd company logo
JavaScript: The Missing Manual Chapter 1: Writing Your First JavaScript Program Author: David S. McFarland | Publisher: O’Reilly Copyright 2010
Introducing Programming JavaScript is can be used to add intelligence to your Web pages JavaScript lets you make your Web pages more engaging and effective Copyright 2010
Introducing Programming As programming languages go, JavaScript is relatively friendly to nonprogrammers Still, JavaScript is more complex than either HTML or CSS and tends to be less intuitive to Web designers Copyright 2010
Introducing Programming Learning JavaScript’s syntax is like learning the vocabulary and grammar of another language Copyright 2010
Client Side vs. Server Side JavaScript is a  client-side  language it works inside of a Web browser (the client) you can view the source code along with HTML and CSS PHP (and other languages) are  server-side only works on the Web server cannot view the source code Copyright 2010
What is a Computer Program? A computer program is a series of steps completed in a designated order When you add JavaScript to a page you are writing a computer program actually, a lite version of a program called a  script Copyright 2010
Compiled vs. Scripting Languages Compiling  is the process of turning code a programmer writes into instructions that a computer can understand A scripting language, like JavaScript, uses an  interpreter  built into all Web browsers an  interpreter  converts the script into something a computer can understand Copyright 2010
How to Add JavaScript to a Page Anatomy of a Web browser: layout  or  rendering   engine the part of a Web browser that understands how to process HTML and CSS interpreter the part of a Web browser that understands how to process JavaScript Copyright 2010
How to Add JavaScript to a Page The  <script>  tag is regular old HTML it acts like a switch use the interpreter, not the rendering engine, to process the code that follows the  </script>  tag is the signal to switch back to using the rendering engine to process HTML and CSS Copyright 2010
How to Add JavaScript to a Page General guidelines #1: <script> placed inside <head> most of the time type  attribute needed for page validation <script> tags are placed after stylesheet information <link /> <style></style> <script type=“text/javascript”></script> Copyright 2010
How to Add JavaScript to a Page My First Internal JavaScript Page . . . <title>My First Internal JavaScript Page</title> <script type=&quot;text/javascript&quot;> alert(&quot;My first internal JavaScript page&quot;); </script> . . . first_internal.html Copyright 2010
How to Add JavaScript to a Page General guidelines #2: When creating an external JavaScript file: cut out all of the code  BETWEEN  the <script> tags, but  NOT INCLUDING  the <script> tags create a new text file with a .js extension use the  scr  attribute in the opening <script> tag to locate the external JavaScript file Copyright 2010
External JavaScript Files My First External JavaScript Page . . . <title>My First External JavaScript Page</title> <script type=&quot;text/javascript“ src=“first_external.js”> </script> . . . first_external.html Copyright 2010
How to Add JavaScript to a Page General guidelines #3: place JavaScript code in external files whenever possible <link /> <style></style> <script type=“text/javascript” src=“file_name.js”> </script> Copyright 2010
How to Add JavaScript to a Page General guidelines #4: place external JavaScript files in a folder (directory) called “scripts” the same way you’d place all images in an “images” directory or stylesheets in a “styles” directory <script type=“text/javascript”  ►  src=“scripts/file_name.js”></script> Copyright 2010
URL Types Three types of paths document-relative src=“scripts/first_external.js” root-relative src=“/scripts/first_external.js” absolute src=“http://gbabon.cdiaweb.com/  ► scripts/first_external.js” url_types.html Copyright 2010
Your First JavaScript  Program Assignment: Download file 1.1.html Add a JavaScript alert message that greets the visitor with “Hello world!”   1.1.html complete_1.1.html Copyright 2010
Writing Text on a Page Walk through: download file 1.2.html add a <script> tag set in the <body> below the <h1> tag set add the following command: document.write(‘<p>Hello world!</p>’);   1.2.html complete_1.2.html Copyright 2010
Writing Text on a Page General guidelines #5: <script> placed inside <head> most of the time Exceptions: when using a  document.write  statement to display an element on the page Copyright 2010
Attaching an External  JavaScript File Brief introduction to  libraries a  library  is a collection of JavaScript code, frequently written by others, and made available for you to use free of charge one increasing popular JavaScript library is called  jQuery Copyright 2010
Attaching an External  JavaScript File Walk through (jQuery striped tables): download file 1.3.html add <script> tags linking to jquery.js file add second set of <script> tags continued . . .   1.3.html complete_1.3.html Copyright 2010
Attaching an External  JavaScript File add the following jQuery code: $(document).ready(function() {   $(‘table.striped tr:even’).addClass(‘even’); });   1.3.html complete_1.3.html Copyright 2010
Tracking Down Errors Most Web browsers are set up to silently ignore JavaScript errors your code simply doesn’t work! no error message to bother the visitor Most Web browsers keep track of errors and record them in a separate window called a  JavaScript console Copyright 2010
JavaScript  Consoles Access the JavaScript console in Firefox: Tools  -> Error Console Access the JavaScript console in Safari: Safari -> Preferences -> Advanced -> Show Develop menu in menu bar Develop -> Show error console Copyright 2010
JavaScript  Consoles Access the JavaScript console in Internet Explorer: type in the URL getfirefox.com! Typical errors to look for: misspellings uneven pairs of ( ), { }, ‘ ’, “ ”, etc. Copyright 2010
JavaScript blah, blah, blah . . . Copyright 2010

More Related Content

PPTX
Introduction to java_script
PDF
JAVA SCRIPT
PPT
Java script
PPT
JAVA SCRIPT
PPT
Java Script
PPTX
Java script
PPTX
Introduction to Java Script
PDF
JavaScript Jump Start 20220214
Introduction to java_script
JAVA SCRIPT
Java script
JAVA SCRIPT
Java Script
Java script
Introduction to Java Script
JavaScript Jump Start 20220214

What's hot (17)

DOC
Java script by Act Academy
PDF
Node.js Crash Course (Jump Start)
PPT
Java script programs
PPTX
Java Script
PPT
Java script
PDF
Introduction to Javascript programming
PPTX
Java Script
PPT
Java script
PPTX
Java script session 3
PPTX
Java script Basic
PPT
Java script
PPT
Session vii(java scriptbasics)
PPTX
Java script writing javascript
PDF
Introduction to html & css
PDF
22 j query1
PDF
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Java script by Act Academy
Node.js Crash Course (Jump Start)
Java script programs
Java Script
Java script
Introduction to Javascript programming
Java Script
Java script
Java script session 3
Java script Basic
Java script
Session vii(java scriptbasics)
Java script writing javascript
Introduction to html & css
22 j query1
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Ad

Similar to JavaScript Missing Manual, Ch. 1 (20)

PPTX
JavaScript - Getting Started.pptx
PPTX
Lecture-15.pptx
PPTX
Introduction to Java script for web .pptx
PDF
Intro to Javascript and jQuery
PDF
JS BASICS JAVA SCRIPT SCRIPTING
PDF
WT UNIT 2 presentation :client side technologies JavaScript And Dom
PPTX
WT Module-3.pptx
PPT
Java script
PPTX
Introduction to JavaScript.pptx
PPTX
Java script
PDF
Unit 4(it workshop)
PPTX
JAVASCRIPT 1.pptx.pptx
PDF
&lt;img src="../i/r_14.png" />
PDF
Essential_Javascript_--_A_Javascript_Tutorial
PDF
Essential_Javascript_--_A_Javascript_Tutorial
PDF
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
PPTX
JavaScriptL18 [Autosaved].pptx
PPT
Introduction to Javascript
PDF
Wt unit 2 ppts client sied technology
JavaScript - Getting Started.pptx
Lecture-15.pptx
Introduction to Java script for web .pptx
Intro to Javascript and jQuery
JS BASICS JAVA SCRIPT SCRIPTING
WT UNIT 2 presentation :client side technologies JavaScript And Dom
WT Module-3.pptx
Java script
Introduction to JavaScript.pptx
Java script
Unit 4(it workshop)
JAVASCRIPT 1.pptx.pptx
&lt;img src="../i/r_14.png" />
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
JavaScriptL18 [Autosaved].pptx
Introduction to Javascript
Wt unit 2 ppts client sied technology
Ad

More from Gene Babon (20)

PDF
March Madness pool results | 2025
PDF
Job Search | Tropical Depressions | Bowling Alleys
PDF
Tech Over Fifty Launch Meeting
PDF
Anatomy Virtual Self Study Group NEPHP 2018
PDF
Become a Front End Web Developer
PDF
Navigating a Career in Web Technology
PPTX
Info Session
PPTX
Info session
PDF
Getting Things Done
PDF
jQuery Mobile Hour 4
PDF
Lesson 17
PDF
Lesson 18
PDF
Lesson 17
PDF
Lesson 16
PDF
Lesson 15
PDF
Lesson 11
PDF
Lesson 10
PDF
Lesson 09
PDF
Lesson 05
PDF
Lesson 04
March Madness pool results | 2025
Job Search | Tropical Depressions | Bowling Alleys
Tech Over Fifty Launch Meeting
Anatomy Virtual Self Study Group NEPHP 2018
Become a Front End Web Developer
Navigating a Career in Web Technology
Info Session
Info session
Getting Things Done
jQuery Mobile Hour 4
Lesson 17
Lesson 18
Lesson 17
Lesson 16
Lesson 15
Lesson 11
Lesson 10
Lesson 09
Lesson 05
Lesson 04

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PDF
KodekX | Application Modernization Development
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PPTX
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
How AI Agents Improve Data Accuracy and Consistency in Due Diligence.pdf
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
CIFDAQ's Market Insight: SEC Turns Pro Crypto
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
Chapter 3 Spatial Domain Image Processing.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
madgavkar20181017ppt McKinsey Presentation.pdf
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
Chapter 2 Digital Image Fundamentals.pdf
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Smarter Business Operations Powered by IoT Remote Monitoring
KodekX | Application Modernization Development
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
NewMind AI Weekly Chronicles - August'25 Week I
How AI Agents Improve Data Accuracy and Consistency in Due Diligence.pdf
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
creating-agentic-ai-solutions-leveraging-aws.pdf
Automating ArcGIS Content Discovery with FME: A Real World Use Case

JavaScript Missing Manual, Ch. 1

  • 1. JavaScript: The Missing Manual Chapter 1: Writing Your First JavaScript Program Author: David S. McFarland | Publisher: O’Reilly Copyright 2010
  • 2. Introducing Programming JavaScript is can be used to add intelligence to your Web pages JavaScript lets you make your Web pages more engaging and effective Copyright 2010
  • 3. Introducing Programming As programming languages go, JavaScript is relatively friendly to nonprogrammers Still, JavaScript is more complex than either HTML or CSS and tends to be less intuitive to Web designers Copyright 2010
  • 4. Introducing Programming Learning JavaScript’s syntax is like learning the vocabulary and grammar of another language Copyright 2010
  • 5. Client Side vs. Server Side JavaScript is a client-side language it works inside of a Web browser (the client) you can view the source code along with HTML and CSS PHP (and other languages) are server-side only works on the Web server cannot view the source code Copyright 2010
  • 6. What is a Computer Program? A computer program is a series of steps completed in a designated order When you add JavaScript to a page you are writing a computer program actually, a lite version of a program called a script Copyright 2010
  • 7. Compiled vs. Scripting Languages Compiling is the process of turning code a programmer writes into instructions that a computer can understand A scripting language, like JavaScript, uses an interpreter built into all Web browsers an interpreter converts the script into something a computer can understand Copyright 2010
  • 8. How to Add JavaScript to a Page Anatomy of a Web browser: layout or rendering engine the part of a Web browser that understands how to process HTML and CSS interpreter the part of a Web browser that understands how to process JavaScript Copyright 2010
  • 9. How to Add JavaScript to a Page The <script> tag is regular old HTML it acts like a switch use the interpreter, not the rendering engine, to process the code that follows the </script> tag is the signal to switch back to using the rendering engine to process HTML and CSS Copyright 2010
  • 10. How to Add JavaScript to a Page General guidelines #1: <script> placed inside <head> most of the time type attribute needed for page validation <script> tags are placed after stylesheet information <link /> <style></style> <script type=“text/javascript”></script> Copyright 2010
  • 11. How to Add JavaScript to a Page My First Internal JavaScript Page . . . <title>My First Internal JavaScript Page</title> <script type=&quot;text/javascript&quot;> alert(&quot;My first internal JavaScript page&quot;); </script> . . . first_internal.html Copyright 2010
  • 12. How to Add JavaScript to a Page General guidelines #2: When creating an external JavaScript file: cut out all of the code BETWEEN the <script> tags, but NOT INCLUDING the <script> tags create a new text file with a .js extension use the scr attribute in the opening <script> tag to locate the external JavaScript file Copyright 2010
  • 13. External JavaScript Files My First External JavaScript Page . . . <title>My First External JavaScript Page</title> <script type=&quot;text/javascript“ src=“first_external.js”> </script> . . . first_external.html Copyright 2010
  • 14. How to Add JavaScript to a Page General guidelines #3: place JavaScript code in external files whenever possible <link /> <style></style> <script type=“text/javascript” src=“file_name.js”> </script> Copyright 2010
  • 15. How to Add JavaScript to a Page General guidelines #4: place external JavaScript files in a folder (directory) called “scripts” the same way you’d place all images in an “images” directory or stylesheets in a “styles” directory <script type=“text/javascript” ► src=“scripts/file_name.js”></script> Copyright 2010
  • 16. URL Types Three types of paths document-relative src=“scripts/first_external.js” root-relative src=“/scripts/first_external.js” absolute src=“http://gbabon.cdiaweb.com/ ► scripts/first_external.js” url_types.html Copyright 2010
  • 17. Your First JavaScript Program Assignment: Download file 1.1.html Add a JavaScript alert message that greets the visitor with “Hello world!” 1.1.html complete_1.1.html Copyright 2010
  • 18. Writing Text on a Page Walk through: download file 1.2.html add a <script> tag set in the <body> below the <h1> tag set add the following command: document.write(‘<p>Hello world!</p>’); 1.2.html complete_1.2.html Copyright 2010
  • 19. Writing Text on a Page General guidelines #5: <script> placed inside <head> most of the time Exceptions: when using a document.write statement to display an element on the page Copyright 2010
  • 20. Attaching an External JavaScript File Brief introduction to libraries a library is a collection of JavaScript code, frequently written by others, and made available for you to use free of charge one increasing popular JavaScript library is called jQuery Copyright 2010
  • 21. Attaching an External JavaScript File Walk through (jQuery striped tables): download file 1.3.html add <script> tags linking to jquery.js file add second set of <script> tags continued . . . 1.3.html complete_1.3.html Copyright 2010
  • 22. Attaching an External JavaScript File add the following jQuery code: $(document).ready(function() { $(‘table.striped tr:even’).addClass(‘even’); }); 1.3.html complete_1.3.html Copyright 2010
  • 23. Tracking Down Errors Most Web browsers are set up to silently ignore JavaScript errors your code simply doesn’t work! no error message to bother the visitor Most Web browsers keep track of errors and record them in a separate window called a JavaScript console Copyright 2010
  • 24. JavaScript Consoles Access the JavaScript console in Firefox: Tools -> Error Console Access the JavaScript console in Safari: Safari -> Preferences -> Advanced -> Show Develop menu in menu bar Develop -> Show error console Copyright 2010
  • 25. JavaScript Consoles Access the JavaScript console in Internet Explorer: type in the URL getfirefox.com! Typical errors to look for: misspellings uneven pairs of ( ), { }, ‘ ’, “ ”, etc. Copyright 2010
  • 26. JavaScript blah, blah, blah . . . Copyright 2010