1 / 10

Tutorial 10 – Session 2

Tutorial 10 – Session 2. Programming with JavaScript. Objectives. Learn about JavaScript data types Declare and work with variables Create and call a JavaScript function. Working with Variables. A variable is a named item in a program that stores information

Download Presentation

Tutorial 10 – Session 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 10 – Session 2 Programming with JavaScript

  2. Objectives Learn about JavaScript data types Declare and work with variables Create and call a JavaScript function New Perspectives on HTML and XHTML, Comprehensive

  3. Working with Variables A variable is a named item in a program that stores information Most JavaScript programs use variables to represent values and text strings New Perspectives on HTML and XHTML, Comprehensive

  4. Declaring a JavaScript Variable You can declare variables with any of the following JavaScript commands: var variable; var variable = value; variable = value; where variable is the name of the variable and value is the initial value of the variable. The first command creates the variable without assigning it a value; the second and third commands both create the variable and assign it a value New Perspectives on HTML and XHTML, Comprehensive

  5. Working with Variables and Data JavaScript variable types: Numeric variables String variables Boolean variables Null variables You must declare a variable before using it New Perspectives on HTML and XHTML, Comprehensive

  6. Working with Variables and Data Numeric variable- any number, such as 13, 22.5, etc. Can also be expressed in scientific notation String variable- any group of text characters, such as “Hello” or “Happy Holidays!” Must be enclosed within either double or single quotations (but not both) Boolean variable- accepts only true and false values Null variable- has no value at all New Perspectives on HTML and XHTML, Comprehensive

  7. Working with Variables and Data JavaScript is a weakly typed language The + symbol can be used with either numeric values or text strings var total = 5 + 4; var emLink = "cadler" + "@" + "mpl.gov"; New Perspectives on HTML and XHTML, Comprehensive

  8. Creating a JavaScript Function A function is a collection of commands that performs an action or returns a value A function name identifies a function Parameters are values used by the function The function is executed only when called by another JavaScript command function_name(parameter values) New Perspectives on HTML and XHTML, Comprehensive

  9. Creating a JavaScript Function New Perspectives on HTML and XHTML, Comprehensive

  10. Creating a Function to Return a Value For a function to return a value, it must include a return statement function function_name(parameters){ JavaScript commands return value; } New Perspectives on HTML and XHTML, Comprehensive

More Related