SlideShare a Scribd company logo
1 of 12
Download to read offline
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/

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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 to 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 to 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
 

Recently uploaded

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 

Recently uploaded (20)

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 

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/