SlideShare a Scribd company logo
JavaScript LiteracyIntermediate Language Featuresfor Reading and Understanding JavaScriptDavid Jacobs@MetaThis
Object Literal Notation// create a person objectvarperson = {};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 notationvar person = {firstName: "Joe",lastName: "Jones",    address: {        street: "123 main",        zip: "12345",        state: "MO"          }};
Object Literals with Functions// can include functionsvar person = {firstName: "Joe",lastName: "Jones",    address: {        street: "123 main",        zip: "12345",        state: "MO"          },getFullName: function() {        return this.firstName + " " + this.lastName;    }};Inline function
Object Literals - JSONJSON is a subset of Object Literal notationRequires property names to be in quotesFunctions are not allowedSpecial characters must be escaped/encodedOther than these restrictions, you cansimply think of JSON as a JavaScript objectAll valid JSON is a valid Object Literalvar person = {   "firstName ": "Joe",   "lastName": "Jones",   "address": {  "street": "123 main",  "zip:": "12345",       "state ": "MO"      }getFullName: function() {return …}};
Argumentsfunction doSomething(a, b, c) {// something}// arguments are optionaldoSomething();  //this is valid!// can pass extra argumentsdoSomething("apple", “banana", "cat", "wtf");  //this is also valid!// regardless of declared parameters, functions have access // to all arguments through a special arguments arrayfunction doSomething() {    return arguments[3];  //returns "wtf"}
Object Literals as ArgumentsJavaScript Idiom for Optional Named ParametersFunctions often have an optional “options” or “settings” parameterjQuery.ajax( url, [settings] )Object Literals are often used as constructors, providing or overriding defaultsjQuery.ajax( {url: "test.html", data: myObject, success: alert("success")}  )
ArraysThe 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 nameWhich 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 AndDo you know?Expressions using them can return a non-boolean valueThis is useful// if userInput is null or an empty string, then the Or case // is evaluated and returned as a valuevar name = userInput || "Bob";// conditional execution – validate() is only called if there’s a valuevar valid = userInput && validate(userInput);
FunctionsFunctions are objectsFunctions are valuesCan be assigned to a variableCan be passed to another function as an argumentCan be returned by a functionFunctions are the building blocks of scopeA function created inside a function is a nested scopeThe outer scope is available to the inner scopeThe inner scope is not available to the outer
Function PointersWhat is the $ in jQuery?// in this example, $ is a variable that points to a functionvar $ = 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 };
CallbacksA 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 FunctionsA higher order function is a function that takes or returns a functionAll asynchronous callback-style function calls involve higher order functionsThey are used nearly everywhere in JavaScriptAJAX calls, event handling, Node.js, etcA better understanding of functional programming will improve your JavaScript code and your programming skillsLearn More about Functional JavaScriptArticle: http://www.hunlock.com/blogs/Functional_JavascriptBook:  JavaScript Patterns by StoyanStefanovUnderscore.js An excellent utility library for functional programming in JavaScript:http://documentcloud.github.com/underscore/

More Related Content

What's hot (20)

PDF
Functional Structures in PHP
Marcello Duarte
 
PDF
Php unit the-mostunknownparts
Bastian Feder
 
PDF
Taming Command Bus
Krzysztof Menżyk
 
PPTX
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Doug Jones
 
PDF
Introduction to web programming with JavaScript
T11 Sessions
 
PPTX
Javascript basics for automation testing
Vikas Thange
 
PDF
SOLID Principles
Yi-Huan Chan
 
PPSX
Javascript variables and datatypes
Varun C M
 
PDF
The IoC Hydra
Kacper Gunia
 
PDF
Who killed object oriented design?
Amir Barylko
 
PDF
Basics of JavaScript
Bala Narayanan
 
PDF
SilverStripe CMS JavaScript Refactoring
Ingo Schommer
 
PDF
Intro to Angular.JS Directives
Christian Lilley
 
PDF
Field api.From d7 to d8
Pavel Makhrinsky
 
PDF
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Krzysztof Menżyk
 
PDF
AngularJs
Hossein Baghayi
 
PDF
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
PDF
A Gentle Introduction To Object Oriented Php
Michael Girouard
 
PDF
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia
 
PDF
Symfony World - Symfony components and design patterns
Łukasz Chruściel
 
Functional Structures in PHP
Marcello Duarte
 
Php unit the-mostunknownparts
Bastian Feder
 
Taming Command Bus
Krzysztof Menżyk
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Doug Jones
 
Introduction to web programming with JavaScript
T11 Sessions
 
Javascript basics for automation testing
Vikas Thange
 
SOLID Principles
Yi-Huan Chan
 
Javascript variables and datatypes
Varun C M
 
The IoC Hydra
Kacper Gunia
 
Who killed object oriented design?
Amir Barylko
 
Basics of JavaScript
Bala Narayanan
 
SilverStripe CMS JavaScript Refactoring
Ingo Schommer
 
Intro to Angular.JS Directives
Christian Lilley
 
Field api.From d7 to d8
Pavel Makhrinsky
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Krzysztof Menżyk
 
AngularJs
Hossein Baghayi
 
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
A Gentle Introduction To Object Oriented Php
Michael Girouard
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia
 
Symfony World - Symfony components and design patterns
Łukasz Chruściel
 

Viewers also liked (7)

PPTX
Study Skills - Extended Orientation for New Students
Bodwell High School
 
PPTX
Types of learners
mariamontoy
 
DOC
Fs2.episode2 sarah jane cabilino
Sarah Cabilino
 
DOCX
Field Study 2 Episode 1
Jundel Deliman
 
DOCX
FS 2 episode 1-3
Marian Tiempo
 
DOCX
Field Study 2 Episode 2 Lesson Objectives As My Guiding Star
Ruschelle Cossid
 
DOCX
Field Study 2: FS2 Experiencing the Teaching- Learning Process
Jessa Arnado
 
Study Skills - Extended Orientation for New Students
Bodwell High School
 
Types of learners
mariamontoy
 
Fs2.episode2 sarah jane cabilino
Sarah Cabilino
 
Field Study 2 Episode 1
Jundel Deliman
 
FS 2 episode 1-3
Marian Tiempo
 
Field Study 2 Episode 2 Lesson Objectives As My Guiding Star
Ruschelle Cossid
 
Field Study 2: FS2 Experiencing the Teaching- Learning Process
Jessa Arnado
 
Ad

Similar to JavaScript Literacy (20)

PPT
JavaScript: The Language
Engage Software
 
PPT
JavaScript Needn't Hurt!
Thomas Kjeldahl Nilsson
 
PPTX
OO in JavaScript
Gunjan Kumar
 
PDF
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
PPT
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
KEY
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
PPT
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
PPTX
Lecture 4- Javascript Function presentation
GomathiUdai
 
PPTX
Object oriented java script
vivek p s
 
PPT
Javascript Templating
bcruhl
 
PPT
Basic Javascript
Bunlong Van
 
PPTX
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
PPT
25-functions.ppt
JyothiAmpally
 
PPTX
Awesomeness of JavaScript…almost
Quinton Sheppard
 
PDF
JavaScript Primer
Daniel Cousineau
 
KEY
Week3
Will Gaybrick
 
PPTX
Javascript fundamentals and not
Salvatore Fazio
 
PDF
Javascript & Ajax Basics
Richard Paul
 
PPT
JavaScript Tutorial
Bui Kiet
 
PPTX
JavaScript, Beyond the Curly Braces
Chicago ALT.NET
 
JavaScript: The Language
Engage Software
 
JavaScript Needn't Hurt!
Thomas Kjeldahl Nilsson
 
OO in JavaScript
Gunjan Kumar
 
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
Lecture 4- Javascript Function presentation
GomathiUdai
 
Object oriented java script
vivek p s
 
Javascript Templating
bcruhl
 
Basic Javascript
Bunlong Van
 
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
25-functions.ppt
JyothiAmpally
 
Awesomeness of JavaScript…almost
Quinton Sheppard
 
JavaScript Primer
Daniel Cousineau
 
Javascript fundamentals and not
Salvatore Fazio
 
Javascript & Ajax Basics
Richard Paul
 
JavaScript Tutorial
Bui Kiet
 
JavaScript, Beyond the Curly Braces
Chicago ALT.NET
 
Ad

Recently uploaded (20)

PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
The Future of AI & Machine Learning.pptx
pritsen4700
 

JavaScript Literacy

  • 1. JavaScript LiteracyIntermediate Language Featuresfor Reading and Understanding JavaScriptDavid Jacobs@MetaThis
  • 2. Object Literal Notation// create a person objectvarperson = {};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 notationvar person = {firstName: "Joe",lastName: "Jones", address: { street: "123 main", zip: "12345", state: "MO" }};
  • 3. Object Literals with Functions// can include functionsvar 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 - JSONJSON is a subset of Object Literal notationRequires property names to be in quotesFunctions are not allowedSpecial characters must be escaped/encodedOther than these restrictions, you cansimply think of JSON as a JavaScript objectAll valid JSON is a valid Object Literalvar person = { "firstName ": "Joe", "lastName": "Jones", "address": { "street": "123 main", "zip:": "12345", "state ": "MO" }getFullName: function() {return …}};
  • 5. Argumentsfunction doSomething(a, b, c) {// something}// arguments are optionaldoSomething(); //this is valid!// can pass extra argumentsdoSomething("apple", “banana", "cat", "wtf"); //this is also valid!// regardless of declared parameters, functions have access // to all arguments through a special arguments arrayfunction doSomething() { return arguments[3]; //returns "wtf"}
  • 6. Object Literals as ArgumentsJavaScript Idiom for Optional Named ParametersFunctions often have an optional “options” or “settings” parameterjQuery.ajax( url, [settings] )Object Literals are often used as constructors, providing or overriding defaultsjQuery.ajax( {url: "test.html", data: myObject, success: alert("success")} )
  • 7. ArraysThe 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 nameWhich 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 AndDo you know?Expressions using them can return a non-boolean valueThis is useful// if userInput is null or an empty string, then the Or case // is evaluated and returned as a valuevar name = userInput || "Bob";// conditional execution – validate() is only called if there’s a valuevar valid = userInput && validate(userInput);
  • 9. FunctionsFunctions are objectsFunctions are valuesCan be assigned to a variableCan be passed to another function as an argumentCan be returned by a functionFunctions are the building blocks of scopeA function created inside a function is a nested scopeThe outer scope is available to the inner scopeThe inner scope is not available to the outer
  • 10. Function PointersWhat is the $ in jQuery?// in this example, $ is a variable that points to a functionvar $ = 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. CallbacksA 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 FunctionsA higher order function is a function that takes or returns a functionAll asynchronous callback-style function calls involve higher order functionsThey are used nearly everywhere in JavaScriptAJAX calls, event handling, Node.js, etcA better understanding of functional programming will improve your JavaScript code and your programming skillsLearn More about Functional JavaScriptArticle: http://www.hunlock.com/blogs/Functional_JavascriptBook: JavaScript Patterns by StoyanStefanovUnderscore.js An excellent utility library for functional programming in JavaScript:http://documentcloud.github.com/underscore/