SlideShare a Scribd company logo
JavaScript: The Missing Manual Chapter 2: The Grammar of JavaScript Author: David S. McFarland | Publisher: O’Reilly Copyright 2010
Statements JavaScript statement: a basic programming unit, usually representing a single step in a JavaScript program combine statements to create a JavaScript program each statement ends with a semicolon like a period at the end of a sentence Copyright 2010
Commands Commands are usually called  functions  or  methods like verbs in a sentence, commands get things done Examples: alert(); document.write(); Chapter 3 will focus on  functions . Copyright 2010
Types of Data In JavaScript the three most common types of data are: numbers strings Boolean Copyright 2010
Numbers a  number  is used for counting or calculating Example: document.write(5 + 15) Result: 20 is written to the page Copyright 2010
Strings A  string  is simply a series of letters and other symbols enclosed inside of quote marks you can use either single or double quotes ‘ Welcome back!’ “ Welcome back!” Copyright 2010
Booleans A  Boolean  value is either true or false typically used to make decisions Example: The visitor filled in the “name” textbox . . . true or false? Copyright 2010
Variables A  variable  is a way to store information so that you can use and manipulate it variables  hold information that can vary Think of a variable as a container or basket the container remains the same even if you change the contents of the container Copyright 2010
Creating a Variable Two-step process: declare  the variable name  the variable Example: var score; Copyright 2010
Creating a Variable Rules:  A variable name . . . must begin with a letter, $, or _ can only contain letters, numbers, $, and _ is case sensitive must not be the same as a keyword (reserved words) Google “JavaScript keywords” Copyright 2010
Using Variables Once a variable is created you can store any type of data that you’d like in it var score; var name_first; score = 0; name_first = “Peter”; Copyright 2010
Using Variables Once a variable is created you can store any type of data that you’d like in it var score; score = 0; var score = 0; Copyright 2010 assignment operator
Data Types & Variables Operator  – a symbol or word that can change one or more values into something else used to modify data Copyright 2010
Basic Math Math Operators: Copyright 2010 Result Example Operator 3 15 / 5 / 50 5 * 10 * 20 25 - 5 - 30 5 + 25 +
Order of Operations Some operations take precedence over others . . . Multiplication (*) and division (/)   takes precedence over addition (+) and subtraction (-) Copyright 2010
Order of Operations Use parentheses to group operations Example: 4 + 5 * 10 result: 54 (4 + 5) * 10 result: 90 Copyright 2010
Combining Strings Concatenation  – combining strings by using the + operator var name_first = “Peter”; var name_last = “Kery”; var full_name = name_first + name_last; Copyright 2010
Combining Numbers &  Strings Copyright 2010
Changing the Values in  Variables Example: var score = 0; score = score + 100; Copyright 2010
Shortcuts for Performing  Math Copyright 2010 score = score + 1; score ++; ++ score = score / 10; score /= 10; /= score = score * 10; score *= 10; *= score = score - 1; score --; -- score = score - 10; score -= 10; -= score = score + 10; score += 10; += Alternate Example Operator
Tutorial #1 Using variables to create messages: open file 2.1.html add a <script> element create two variables for first and last name add three document.write statements to print out the full name in a paragraph 2.1.html Copyright 2010
Tutorial #2 Asking for information: open file 2.2.html add a prompt() command to first script:  var name = prompt(“What is your  ►   name?”, “”); 2.2.html Copyright 2010
Tutorial #2 Asking for information (continued): add a document.write statement to second script: document.write(“<p>Welcome” +  ► name + “</p>” ); 2.2.html Copyright 2010
Arrays Copyright 2010
Creating an Array Copyright 2010
Assessing Items in an  Array Copyright 2010
Adding Items to an Array Copyright 2010
Deleting Items from an  Array Copyright 2010
Adding & Deleting with  splice() Copyright 2010
Tutorial #3 Writing to a Web page using arrays 2.3.html Copyright 2010
Comments A  comment  is simply a line or more of notes interpreter ignores comments useful reminders for how the script works Copyright 2010
Comments Styles: // This is a comment. /* This is also a comment that covers multiple lines */ Copyright 2010
Comments Examples: // create a variable for first name. var name_first; // remember no SINs /* The purpose of this script is to capture the visitors name and print it back to the page. */ Copyright 2010
JavaScript blah, blah, blah . . . Copyright 2010

More Related Content

PPTX
Oop concept in c++ by MUhammed Thanveer Melayi
PPTX
F# Console class
PPTX
Mca ii dfs u-2 array records and pointer
PDF
Amusing C#
ODP
Object Oriented Programming With PHP 5 #2
PDF
Function overloading ppt
PPT
Ext Js Dom Helper
Oop concept in c++ by MUhammed Thanveer Melayi
F# Console class
Mca ii dfs u-2 array records and pointer
Amusing C#
Object Oriented Programming With PHP 5 #2
Function overloading ppt
Ext Js Dom Helper

What's hot (18)

PPT
Ext Js Dom Navigation
DOCX
Declaration programming 2017
PPT
KEY
Clean code and Code Smells
PPTX
Namespace in C++ Programming Language
PPTX
Code smells and remedies
PPTX
PPTX
Computer data type and Terminologies
PDF
C++ Course - Lesson 3
PPT
Enumerated data types in C
PPTX
The NuGram dynamic grammar language
PPT
Coding Standards & Best Practices for iOS/C#
PDF
Function overloading
PPT
SE Michigan PowerShell Users Group - Regex Part1
PDF
Decaf language specification
PPT
iOS Application Development
Ext Js Dom Navigation
Declaration programming 2017
Clean code and Code Smells
Namespace in C++ Programming Language
Code smells and remedies
Computer data type and Terminologies
C++ Course - Lesson 3
Enumerated data types in C
The NuGram dynamic grammar language
Coding Standards & Best Practices for iOS/C#
Function overloading
SE Michigan PowerShell Users Group - Regex Part1
Decaf language specification
iOS Application Development
Ad

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

PPTX
Javascript 101
PPTX
Introduction to Client-Side Javascript
PPSX
DIWE - Programming with JavaScript
DOC
Java script questions
PPTX
JavaScript / Web Engineering / Web Development / html + css + js/presentation
PPTX
JavaScripts & jQuery
PPT
Javascript
PDF
Intro to Programming for Communicators - Hacks/Hackers ATX
PPTX
CSC PPT 13.pptx
PPTX
BITM3730 10-3.pptx
PPTX
BITM3730 10-4.pptx
PDF
PPSX
Javascript variables and datatypes
PPTX
1-JAVA SCRIPT. servere-side applications vs client side applications
PDF
Javascript - Tutorial
PDF
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
PPTX
Java Script Basic to Advanced For Beginner to Advanced Learner.pptx
PPTX
Web programming
PDF
Google maps
PPTX
Java script
Javascript 101
Introduction to Client-Side Javascript
DIWE - Programming with JavaScript
Java script questions
JavaScript / Web Engineering / Web Development / html + css + js/presentation
JavaScripts & jQuery
Javascript
Intro to Programming for Communicators - Hacks/Hackers ATX
CSC PPT 13.pptx
BITM3730 10-3.pptx
BITM3730 10-4.pptx
Javascript variables and datatypes
1-JAVA SCRIPT. servere-side applications vs client side applications
Javascript - Tutorial
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
Java Script Basic to Advanced For Beginner to Advanced Learner.pptx
Web programming
Google maps
Java script
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
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Advanced IT Governance
PPTX
Cloud computing and distributed systems.
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Newfamily of error-correcting codes based on genetic algorithms
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Omni-Path Integration Expertise Offered by Nor-Tech
PPTX
Understanding_Digital_Forensics_Presentation.pptx
madgavkar20181017ppt McKinsey Presentation.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Dropbox Q2 2025 Financial Results & Investor Presentation
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Advanced IT Governance
Cloud computing and distributed systems.
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Newfamily of error-correcting codes based on genetic algorithms
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Advanced Soft Computing BINUS July 2025.pdf
KodekX | Application Modernization Development
NewMind AI Monthly Chronicles - July 2025
Event Presentation Google Cloud Next Extended 2025
Reimagining Insurance: Connected Data for Confident Decisions.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Omni-Path Integration Expertise Offered by Nor-Tech
Understanding_Digital_Forensics_Presentation.pptx

JavaScript Missing Manual, Ch. 2

  • 1. JavaScript: The Missing Manual Chapter 2: The Grammar of JavaScript Author: David S. McFarland | Publisher: O’Reilly Copyright 2010
  • 2. Statements JavaScript statement: a basic programming unit, usually representing a single step in a JavaScript program combine statements to create a JavaScript program each statement ends with a semicolon like a period at the end of a sentence Copyright 2010
  • 3. Commands Commands are usually called functions or methods like verbs in a sentence, commands get things done Examples: alert(); document.write(); Chapter 3 will focus on functions . Copyright 2010
  • 4. Types of Data In JavaScript the three most common types of data are: numbers strings Boolean Copyright 2010
  • 5. Numbers a number is used for counting or calculating Example: document.write(5 + 15) Result: 20 is written to the page Copyright 2010
  • 6. Strings A string is simply a series of letters and other symbols enclosed inside of quote marks you can use either single or double quotes ‘ Welcome back!’ “ Welcome back!” Copyright 2010
  • 7. Booleans A Boolean value is either true or false typically used to make decisions Example: The visitor filled in the “name” textbox . . . true or false? Copyright 2010
  • 8. Variables A variable is a way to store information so that you can use and manipulate it variables hold information that can vary Think of a variable as a container or basket the container remains the same even if you change the contents of the container Copyright 2010
  • 9. Creating a Variable Two-step process: declare the variable name the variable Example: var score; Copyright 2010
  • 10. Creating a Variable Rules: A variable name . . . must begin with a letter, $, or _ can only contain letters, numbers, $, and _ is case sensitive must not be the same as a keyword (reserved words) Google “JavaScript keywords” Copyright 2010
  • 11. Using Variables Once a variable is created you can store any type of data that you’d like in it var score; var name_first; score = 0; name_first = “Peter”; Copyright 2010
  • 12. Using Variables Once a variable is created you can store any type of data that you’d like in it var score; score = 0; var score = 0; Copyright 2010 assignment operator
  • 13. Data Types & Variables Operator – a symbol or word that can change one or more values into something else used to modify data Copyright 2010
  • 14. Basic Math Math Operators: Copyright 2010 Result Example Operator 3 15 / 5 / 50 5 * 10 * 20 25 - 5 - 30 5 + 25 +
  • 15. Order of Operations Some operations take precedence over others . . . Multiplication (*) and division (/) takes precedence over addition (+) and subtraction (-) Copyright 2010
  • 16. Order of Operations Use parentheses to group operations Example: 4 + 5 * 10 result: 54 (4 + 5) * 10 result: 90 Copyright 2010
  • 17. Combining Strings Concatenation – combining strings by using the + operator var name_first = “Peter”; var name_last = “Kery”; var full_name = name_first + name_last; Copyright 2010
  • 18. Combining Numbers & Strings Copyright 2010
  • 19. Changing the Values in Variables Example: var score = 0; score = score + 100; Copyright 2010
  • 20. Shortcuts for Performing Math Copyright 2010 score = score + 1; score ++; ++ score = score / 10; score /= 10; /= score = score * 10; score *= 10; *= score = score - 1; score --; -- score = score - 10; score -= 10; -= score = score + 10; score += 10; += Alternate Example Operator
  • 21. Tutorial #1 Using variables to create messages: open file 2.1.html add a <script> element create two variables for first and last name add three document.write statements to print out the full name in a paragraph 2.1.html Copyright 2010
  • 22. Tutorial #2 Asking for information: open file 2.2.html add a prompt() command to first script: var name = prompt(“What is your ► name?”, “”); 2.2.html Copyright 2010
  • 23. Tutorial #2 Asking for information (continued): add a document.write statement to second script: document.write(“<p>Welcome” + ► name + “</p>” ); 2.2.html Copyright 2010
  • 25. Creating an Array Copyright 2010
  • 26. Assessing Items in an Array Copyright 2010
  • 27. Adding Items to an Array Copyright 2010
  • 28. Deleting Items from an Array Copyright 2010
  • 29. Adding & Deleting with splice() Copyright 2010
  • 30. Tutorial #3 Writing to a Web page using arrays 2.3.html Copyright 2010
  • 31. Comments A comment is simply a line or more of notes interpreter ignores comments useful reminders for how the script works Copyright 2010
  • 32. Comments Styles: // This is a comment. /* This is also a comment that covers multiple lines */ Copyright 2010
  • 33. Comments Examples: // create a variable for first name. var name_first; // remember no SINs /* The purpose of this script is to capture the visitors name and print it back to the page. */ Copyright 2010
  • 34. JavaScript blah, blah, blah . . . Copyright 2010