SlideShare una empresa de Scribd logo
1 de 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/

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Último

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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 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/