Javascript foundations: variables and types

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Javascript foundations: variables and types - Presentation Transcript

    1. variables & types Learning Javascript foundations John Hunter 5 July 2008 1
    2. var message = 'Hello'; ...we’ve declared a variable - identified as message - and assigned it a value of ‘Hello’ 2
    3. variable identifier value message 'Hello' type of: String 3
    4. types type examples String ' Apples' \"42\" Number 42 3.12 -9 Boolean true false Object (?) Array (?) ... ... 4
    5. Array doors 4 0 red colours 1 green 2 blue model ‘Mazda6’ 3 yellow Numbers, Booleans and Strings can be considered primitive types Arrays and Objects are reference types 5
    6. Javascript is a loosely typed language: a variable can contain any type of value at any time. 6
    7. var pie = 'Apple'; // contains a string pie = 3.12; // contains a number pie = true; // contains a boolean pie = someOtherVariable; // contains who knows pie can hold any value type at any time 7
    8. Javascript has a simple way to define a value and its type in one: literals 8
    9. var message = 'Hello'; // string literal var count = 26; // number literal var height = 102.23; // number literal var isFinished = false; // boolean literal this is a familiar way to create primitive values 9
    10. var letters = ['a', 'b', 'c']; // array literal var ages = [26, 31, 23, 42]; // array literal var point = {x: 232, y: 102}; // object literal var bookmark = { name: 'Google', url: 'http://google.com/', lastVisited: '20080518', }; // object literal objects and arrays are easy to create using literals 10
    11. var letters = ['a', 'b', 'c']; Array 0 a letters 1 b 2 c the letters variable contains a reference to the array 11
    12. var point = {x: 232, y: 102}; Object x 232 point y 102 the point variable contains a reference to the object 12
    13. var bookmark = { name: 'Google', url: 'http://google.com/', lastVisited: '20080518', }; Object name Google' bookmark url 'http://google.com/' lastVisited 20080518' 13
    14. Object name Google' bookmark url 'http://google.com/' lastVisited 20080518' // alternative creation using the Object constructor var bookmark = new Object(); bookmark.name = 'Google'; bookmark.url = 'http://google.com/'; bookmark.lastVisited = '20080518'; 14
    15. object literal: object constructor: cleaner, easier ugly var bookmark = new Object(); var bookmark = { bookmark.name = 'Google'; name: 'Google', bookmark.url = 'http://google.com/'; url: 'http://google.com/', bookmark.lastVisited = '20080518'; lastVisited: '20080518', }; 15
    16. Review variables consist of an identifier and a value values have a type (e.g. string, number) values are primitive or reference types dynamic - variables can change value and type literals define both type and value in one object literals make it easy to create objects 16
    17. Thanks 17

    + John HunterJohn Hunter, 9 months ago

    custom

    820 views, 2 favs, 0 embeds more stats

    This presentation forms part of a tutorial on learn more

    More info about this document

    CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

    Go to text version

    • Total Views 820
      • 820 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories