SlideShare une entreprise Scribd logo
1  sur  12
JavaScript LiteracyIntermediate Language Featuresfor Reading and Understanding JavaScript David Jacobs @MetaThis
Object Literal Notation // create a person object varperson = {}; person.firstName = "Joe"; person.lastName = "Jones"; person.address = {}; person.address.street = "123 main"; person.address.zip = "12345"; person.address.state = "MO"; // same thing in object literal notation var person = { firstName: "Joe", lastName: "Jones",     address: {         street: "123 main",         zip: "12345",         state: "MO"           } };
Object Literals with Functions // can include functions var person = { firstName: "Joe", lastName: "Jones",     address: {         street: "123 main",         zip: "12345",         state: "MO"           }, getFullName: function() {         return this.firstName + " " + this.lastName;     } }; Inline function
Object Literals - JSON JSON is a subset of Object Literal notation Requires property names to be in quotes Functions are not allowed Special characters must be escaped/encoded Other than these restrictions, you can simply think of JSON as a JavaScript object All valid JSON is a valid Object Literal var person = {    "firstName ": "Joe",    "lastName": "Jones",    "address": {   "street": "123 main",   "zip:": "12345",        "state ": "MO"       } getFullName: function() { return … } };
Arguments function doSomething(a, b, c) { // something } // arguments are optional doSomething();  //this is valid! // can pass extra arguments doSomething("apple", “banana", "cat", "wtf");  //this is also valid! // regardless of declared parameters, functions have access  // to all arguments through a special arguments array function doSomething() {     return arguments[3];  //returns "wtf" }
Object Literals as Arguments JavaScript Idiom for Optional Named Parameters Functions often have an optional “options” or “settings” parameter jQuery.ajax( url, [settings] ) Object Literals are often used as constructors, providing or overriding defaults jQuery.ajax( {url: "test.html", data: myObject, success: alert("success")}  )
Arrays The Array prototype contains methods specific to arrays, but as a data structure… Arrays are essentially just object literals with an implicit number as the property name Which generalizes to a universal property:value pattern for all objects (and JSON data) Which enables a universal data access pattern of object[property] var array = ["first","second", "third"]; var object = {0: "first", 1: "second", 2: "third"}; array[1]     //returns "second" object[1]   //returns "second“ Don’t take this point too literally…but it may help you better understand JavaScript data structures.
|| and && You know || is a boolean Or && is a boolean And Do you know? Expressions using them can return a non-boolean value This is useful // if userInput is null or an empty string, then the Or case  // is evaluated and returned as a value var name = userInput || "Bob"; // conditional execution – validate() is only called if there’s a value var valid = userInput && validate(userInput);
Functions Functions are objects Functions are values Can be assigned to a variable Can be passed to another function as an argument Can be returned by a function Functions are the building blocks of scope A function created inside a function is a nested scope The outer scope is available to the inner scope The inner scope is not available to the outer
Function Pointers What is the $ in jQuery? // in this example, $ is a variable that points to a function var $ = function (id) {    return document.getElementById(id);  };    // this is a function call on the $ variable, setting the onClick handler  // on the DOM element returned by the function $('yourDiv').onClick = function (event) {     //do something  };
Callbacks A callback is just a function that is passed to another function, typically with the intent of it being called later (“called back”) TIP: Callbacks are often easier to understand if you use function pointers (assigning a function to a variable) instead of creating an anonymous function on-the-spot.
Higher Order Functions A higher order function is a function that takes or returns a function All asynchronous callback-style function calls involve higher order functions They are used nearly everywhere in JavaScript AJAX calls, event handling, Node.js, etc A better understanding of functional programming will improve your JavaScript code and your programming skills Learn More about Functional JavaScript Article: http://www.hunlock.com/blogs/Functional_Javascript Book:  JavaScript Patterns by StoyanStefanov Underscore.js  An excellent utility library for functional programming in JavaScript: http://documentcloud.github.com/underscore/

Contenu connexe

Tendances

Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHPMarcello Duarte
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownpartsBastian Feder
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScriptT11 Sessions
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?Amir Barylko
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringIngo Schommer
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS DirectivesChristian Lilley
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Krzysztof Menżyk
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpMichael Girouard
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needKacper Gunia
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsŁukasz Chruściel
 

Tendances (20)

Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Taming Command Bus
Taming Command BusTaming Command Bus
Taming Command Bus
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript Refactoring
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
 
Field api.From d7 to d8
Field api.From d7 to d8Field api.From d7 to d8
Field api.From d7 to d8
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
 
AngularJs
AngularJsAngularJs
AngularJs
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 

En vedette

Study Skills - Extended Orientation for New Students
Study Skills - Extended Orientation for New StudentsStudy Skills - Extended Orientation for New Students
Study Skills - Extended Orientation for New StudentsBodwell High School
 
Types of learners
Types of learnersTypes of learners
Types of learnersmariamontoy
 
Fs2.episode2 sarah jane cabilino
Fs2.episode2 sarah jane cabilinoFs2.episode2 sarah jane cabilino
Fs2.episode2 sarah jane cabilinoSarah Cabilino
 
Field Study 2 Episode 1
Field Study 2 Episode 1Field Study 2 Episode 1
Field Study 2 Episode 1Jundel Deliman
 
Field Study 2 Episode 2 Lesson Objectives As My Guiding Star
Field Study 2 Episode 2 Lesson Objectives As My Guiding StarField Study 2 Episode 2 Lesson Objectives As My Guiding Star
Field Study 2 Episode 2 Lesson Objectives As My Guiding StarRuschelle Cossid
 
Field Study 2: FS2 Experiencing the Teaching- Learning Process
Field Study 2: FS2 Experiencing the Teaching- Learning ProcessField Study 2: FS2 Experiencing the Teaching- Learning Process
Field Study 2: FS2 Experiencing the Teaching- Learning ProcessJessa Arnado
 

En vedette (7)

Study Skills - Extended Orientation for New Students
Study Skills - Extended Orientation for New StudentsStudy Skills - Extended Orientation for New Students
Study Skills - Extended Orientation for New Students
 
Types of learners
Types of learnersTypes of learners
Types of learners
 
Fs2.episode2 sarah jane cabilino
Fs2.episode2 sarah jane cabilinoFs2.episode2 sarah jane cabilino
Fs2.episode2 sarah jane cabilino
 
Field Study 2 Episode 1
Field Study 2 Episode 1Field Study 2 Episode 1
Field Study 2 Episode 1
 
FS 2 episode 1-3
FS 2 episode 1-3FS 2 episode 1-3
FS 2 episode 1-3
 
Field Study 2 Episode 2 Lesson Objectives As My Guiding Star
Field Study 2 Episode 2 Lesson Objectives As My Guiding StarField Study 2 Episode 2 Lesson Objectives As My Guiding Star
Field Study 2 Episode 2 Lesson Objectives As My Guiding Star
 
Field Study 2: FS2 Experiencing the Teaching- Learning Process
Field Study 2: FS2 Experiencing the Teaching- Learning ProcessField Study 2: FS2 Experiencing the Teaching- Learning Process
Field Study 2: FS2 Experiencing the Teaching- Learning Process
 

Similaire à JavaScript Literacy

The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery PresentationSony Jain
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyHuiyi Yan
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsColin DeCarlo
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Javascript Primer
Javascript PrimerJavascript Primer
Javascript PrimerAdam Hepton
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oopLearningTech
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templatingbcruhl
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxSHIVA101531
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretssmueller_sandsmedia
 

Similaire à JavaScript Literacy (20)

The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery Presentation
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Javascript Primer
Javascript PrimerJavascript Primer
Javascript Primer
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 

Dernier

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Dernier (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

JavaScript Literacy

  • 1. JavaScript LiteracyIntermediate Language Featuresfor Reading and Understanding JavaScript David Jacobs @MetaThis
  • 2. Object Literal Notation // create a person object varperson = {}; person.firstName = "Joe"; person.lastName = "Jones"; person.address = {}; person.address.street = "123 main"; person.address.zip = "12345"; person.address.state = "MO"; // same thing in object literal notation var person = { firstName: "Joe", lastName: "Jones", address: { street: "123 main", zip: "12345", state: "MO" } };
  • 3. Object Literals with Functions // can include functions var person = { firstName: "Joe", lastName: "Jones", address: { street: "123 main", zip: "12345", state: "MO" }, getFullName: function() { return this.firstName + " " + this.lastName; } }; Inline function
  • 4. Object Literals - JSON JSON is a subset of Object Literal notation Requires property names to be in quotes Functions are not allowed Special characters must be escaped/encoded Other than these restrictions, you can simply think of JSON as a JavaScript object All valid JSON is a valid Object Literal var person = { "firstName ": "Joe", "lastName": "Jones", "address": { "street": "123 main", "zip:": "12345", "state ": "MO" } getFullName: function() { return … } };
  • 5. Arguments function doSomething(a, b, c) { // something } // arguments are optional doSomething(); //this is valid! // can pass extra arguments doSomething("apple", “banana", "cat", "wtf"); //this is also valid! // regardless of declared parameters, functions have access // to all arguments through a special arguments array function doSomething() { return arguments[3]; //returns "wtf" }
  • 6. Object Literals as Arguments JavaScript Idiom for Optional Named Parameters Functions often have an optional “options” or “settings” parameter jQuery.ajax( url, [settings] ) Object Literals are often used as constructors, providing or overriding defaults jQuery.ajax( {url: "test.html", data: myObject, success: alert("success")} )
  • 7. Arrays The Array prototype contains methods specific to arrays, but as a data structure… Arrays are essentially just object literals with an implicit number as the property name Which generalizes to a universal property:value pattern for all objects (and JSON data) Which enables a universal data access pattern of object[property] var array = ["first","second", "third"]; var object = {0: "first", 1: "second", 2: "third"}; array[1] //returns "second" object[1] //returns "second“ Don’t take this point too literally…but it may help you better understand JavaScript data structures.
  • 8. || and && You know || is a boolean Or && is a boolean And Do you know? Expressions using them can return a non-boolean value This is useful // if userInput is null or an empty string, then the Or case // is evaluated and returned as a value var name = userInput || "Bob"; // conditional execution – validate() is only called if there’s a value var valid = userInput && validate(userInput);
  • 9. Functions Functions are objects Functions are values Can be assigned to a variable Can be passed to another function as an argument Can be returned by a function Functions are the building blocks of scope A function created inside a function is a nested scope The outer scope is available to the inner scope The inner scope is not available to the outer
  • 10. Function Pointers What is the $ in jQuery? // in this example, $ is a variable that points to a function var $ = function (id) { return document.getElementById(id); }; // this is a function call on the $ variable, setting the onClick handler // on the DOM element returned by the function $('yourDiv').onClick = function (event) { //do something };
  • 11. Callbacks A callback is just a function that is passed to another function, typically with the intent of it being called later (“called back”) TIP: Callbacks are often easier to understand if you use function pointers (assigning a function to a variable) instead of creating an anonymous function on-the-spot.
  • 12. Higher Order Functions A higher order function is a function that takes or returns a function All asynchronous callback-style function calls involve higher order functions They are used nearly everywhere in JavaScript AJAX calls, event handling, Node.js, etc A better understanding of functional programming will improve your JavaScript code and your programming skills Learn More about Functional JavaScript Article: http://www.hunlock.com/blogs/Functional_Javascript Book: JavaScript Patterns by StoyanStefanov Underscore.js An excellent utility library for functional programming in JavaScript: http://documentcloud.github.com/underscore/