SlideShare a Scribd company logo
1 of 92
JavaScript  Needn’t Hurt! Thomas Kjeldahl Nilsson [email_address] linkedin.com/in/thomaskjeldahlnilsson twitter.com/thomanil
Intro
Who Are You? Done any JavaScript? Dozen lines of code? Hundreds?   Thousands?
Who Am I? JavaScript enthusiast Hundreds of hours Thousands lines of code Not an expert!
What Are We Covering Today? Language basics Html scripting Good practices Tools
Practical Stuff
History Lesson
 
Brendan Eich
ECMAScript
A Note on ActionScript
What Rocks? Powerful, elegant, dynamic Present & enabled for most users Not confined to the browser Small learning surface
What Sucks? Rushed out the door Some bad language features Crossbrowser problems
Development Environment Walkthrough
Language Basics Syntax Types Variables Objects Functions
Basic Syntax Similar to Java, C# Operators, statements if-else, while, for, try-catch-finally Still in Kansas...
Types Strings Numbers Booleans Objects Arrays
Variable Declarations var x = “foo”;  // string var x = 2;  // number var x = true;  // boolean var x = { };  // object var x = [ ];  // array
Objects
Object Creation Literal Form var BasicProject = { name : "Steria Workshop", version : 1.2, getName : function() { return this.name; } };
Object Creation Dynamic Form var BasicProject = {}; BasicProject.name = "Steria Workshop"; BasicProject.version = 1.2; BasicProject.getName = function() { return this.name; };
Objects as Maps (Associative Arrays) var Person = { firstname:"John", lastname:"Smith" }; Person.firstname;  // => "John" (Access using identifier) Person["firstname"];  // => "John" (Access using variable name)
Arrays are Special Case of Object var arr = [];  // Always declared without size.  // Grows as needed. arr[0] = true; arr[3] = "john"; arr[300] = { description : "object!" }; arr[100];  // => Undefined  arr.length;  // => 301
Arrays and Objects Can Be Deeply Nested var OuterObject = { innerArray : [ innerObject : { deepestArray : [1,2,3] } ] };
JSON {"firstName":"Gustav","lastName":"Adolf", "roles":["King of Sweden","Terrible shipbuilder"], "other":{"birth":"9.12.1594","death":"16.11.1632"}}
Kind Familiar Looking { "firstName" : "Gustav", "lastName" : "Adolf", "roles" : [ "King of Sweden",  "Terrible shipbuilder" ], "other" : { "birth" : "9.12.1594", "death" : "16.11.1632" } }
JavaScript Object Literal! var EvaluatedObject =  { firstName : "Gustav", lastName : "Adolf", roles : [ "King of Sweden",  "Terrible shipbuilder" ], other : { birth : "9.12.1594", death : "16.11.1632" } } ;
Inheritance
Prototypal Inheritance (Simplified) var Employee = {name : "CEO Jack", company : "ACME Inc."}; var Janitor = Object.create(Employee); // Janitor now looks and behaves just like its prototype, Employee Janitor.company // =>  "ACME Inc.", falls back to prototype.company Janitor.name = "Janitor Tim"; // Override name Janitor.tools = ["broom", "bucket"]; // Define member variable only on child Employee.name = "CEO Jane"; // Change name of prototype Janitor.name; // => Still "Janitor Tim". Overriden members unaffected by prototype changes
Functions
Simple Function Definition function add(a, b) { return a + b; }
That's Just a  Way of Saying:  var add = function(a, b) { return a + b; }; // Use this consistently // Helps you remember: // Functions are just variables!
An Anonymous Function... function(element) { // Do something with element }
...Can Be Sent To Another Function each(collection, function(element) { // Do something with current element });
Example: Event Handler button.onClick(function(element) { alert(«You clicked me!»); });
Sharp Edges Global variables No block s cope Semicolon insertion == operator
Properly Scoped Variable var getSmallNumber = function(){ var  smallNumber = 42; // Note use of  var  keyword return smallNumber; };
Sloppy, Global Variable var getSmallNumber = function(){ smallNumber = 42;  return smallNumber; }; // Missing var prefix = smallNumber gets global scope // Becomes available for all code // Sticks around and pollutes namespace
No Block Scope var x = 1; if (true) { var x = 123; } // x => 123
Semicolon insertion Don't force the browser to guess!
Example a = b + c (d + e).print() becomes... a = b + c(d + e).print();
== vs ===
Quiz '' == '0'  // true or false? 0 == ''  // true or false? 0 == '0'  // true or false? false == 'false'  // true or false? false == '0'  // true or false? false == undefined  // true or false? false == null  // true or false? null == undefined  // true or false? '  ' == 0  // true or false?
How Many Did You Get? '' == '0'  // false 0 == ''  // true 0 == '0'  // true false == 'false'  // false false == '0'  // true false == undefined  // false false == null  // false null == undefined  // true '  ' == 0  // true // Why? Type coercion on right operand, that's why.
Instead, Use === (And !==)  '' === '0'  // false 0 === ''  // false 0 === '0'  // false false === 'false'  // false false === '0'  // false false === undefined  // false false === null  // false null === undefined  // false '  ' === 0  // false
Advanced Stuff Closures Modules Memoization
Clientside Firebug jQuery
Firebug Demo
The DOM
 
<TABLE>   <TBODY>    <TR>    <TD>Shady Grove</TD>   <TD>Aeolian</TD>    </TR>    <TR>   <TD>Over the River, Charlie</TD>    <TD>Dorian</TD>    </TR>    </TBODY>   </TABLE>
 
DOM Scripting Basics x.getElementById(id) ; // get the element with a specified id x.getElementsByTagName(name);  // get all elements with a    // specified tag name x.appendChild(node);   // insert a child node to x x.removeChild(node), // remove a child node from x x.innerHTML = «<p>New text</p>»; // fill element with html or text
Live Example
DOM Api: Crossbrowser Headache http://www.quirksmode.org
So Use a Framework!
jQuery
Instant Win: Crossbrowser Non-verbose Traverse DOM Manipulate DOM
Lots of Other Stuff, Too Server communication UI widgets and effects each(), map(), etc JSON parsing +++
jQuery Function $()  // Short form jQuery() // Long form
Find Stuff $(“p”);    // Find all paragraphs $(“#shoppingList”);  // Find element with id 'shoppingList' $(“.shoppingListItem”); // Find elements with class 'shoppingListItem' $(“:text”);   // Find all text elements $(“:visible”);   // Find only visible elements
$() Wraps and Returns Matching Element(s)
Manipulate Matched DOM Elements $(“p”).css(”color”, ”green”);  // Set color on all paragraph elements $(“p”).hide();  // Hide all paragraphs // Make all input buttons react to mouse clicks $(“input”).click(function(){ alert(”You clicked this button!”); });
Chaining Every API call returns jQuery object So we can chain function calls together “Fluent API”
Chaining Example // Set color on all paragraph elements, then hide them all $(“p”).css(”color”, ”green”).hide();
Live Example
Prepared Example
Caution! Use frameworks as needed But don't depend on them! JavaScript != jQuery
Good Practices jsLint Automated testing Unobtrusive JavaScript
JsLint Demo
Automated Testing YUI Test demo
Unobtrusive JavaScript Structure vs behavior Separate js files Event handler setup Namespaces Universal Access
 
 
 
 
 
Namespace Hygiene All your code within single object
Universal Access Can all your users use your site? Users without JS? Blind users with screen readers? Use progressive enhancement
Crossbrowser Dev Process Frameworks > raw DOM Test early, test often  Clean, disciplined code
Let’s Code! Exercises
Wrap-up
What Did We Cover Today? Language basics Html scripting Good practices Tools
What´s Missing? Server Communication Performance Security Practice practice practice!
References & Further Studies
 
 
Web Resources http://javascript.crockford.com http://cjohansen.no/javascript http://developer.yahoo.com/yui/theater http://ajaxian.com
Best Way to Learn: Start Building! http://ajaxian.com/archives/writing-a-javascript-tetris-lessons-learned-from-a-ruby-chap
Download This Workshop http://kjeldahlnilsson.net/jsnh.zip Slides, lecture notes, exercises Creative Commons license Use and distribute freely... ...or have me present it for you on-site :)
Q&A  Discussion
Contact Info [email_address] linkedin.com/in/thomaskjeldahlnilsson twitter.com/thomanil

More Related Content

What's hot

Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)James Titcumb
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryGunjan Kumar
 
Javascript 2009
Javascript 2009Javascript 2009
Javascript 2009borkweb
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)James Titcumb
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript SecurityJohannes Hoppe
 
Crafting Quality PHP Applications (PHP Benelux 2018)
Crafting Quality PHP Applications (PHP Benelux 2018)Crafting Quality PHP Applications (PHP Benelux 2018)
Crafting Quality PHP Applications (PHP Benelux 2018)James Titcumb
 
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010Sergey Ilinsky
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Jaroslaw Palka
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesRobert Nyman
 
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)James Titcumb
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming Enguest9bcef2f
 
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)James Titcumb
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)Addy Osmani
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)James Titcumb
 
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)James Titcumb
 

What's hot (20)

Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)
 
JavaScript Patterns
JavaScript PatternsJavaScript Patterns
JavaScript Patterns
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Element
ElementElement
Element
 
Javascript 2009
Javascript 2009Javascript 2009
Javascript 2009
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
Crafting Quality PHP Applications (PHP Benelux 2018)
Crafting Quality PHP Applications (PHP Benelux 2018)Crafting Quality PHP Applications (PHP Benelux 2018)
Crafting Quality PHP Applications (PHP Benelux 2018)
 
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014
 
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of ChocolatesJavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
 
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming En
 
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
Ampersandjs
AmpersandjsAmpersandjs
Ampersandjs
 
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
 

Similar to JavaScript Needn't Hurt!

Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS FrameworkMohd Imran
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITPLecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITPyucefmerhi
 
Javascript Primer
Javascript PrimerJavascript Primer
Javascript PrimerAdam Hepton
 
Javascript Experiment
Javascript ExperimentJavascript Experiment
Javascript Experimentwgamboa
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
Ods Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A TutorialOds Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A Tutorialsimienc
 
jQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsEugene Andruszczenko
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryRefresh Events
 
Migration testing framework
Migration testing frameworkMigration testing framework
Migration testing frameworkIndicThreads
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rulesnagarajhubli
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Davide Cerbo
 

Similar to JavaScript Needn't Hurt! (20)

Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITPLecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITP
 
Javascript Primer
Javascript PrimerJavascript Primer
Javascript Primer
 
Javascript Experiment
Javascript ExperimentJavascript Experiment
Javascript Experiment
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Ods Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A TutorialOds Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A Tutorial
 
jQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh Events
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQuery
 
SlideShare Instant
SlideShare InstantSlideShare Instant
SlideShare Instant
 
SlideShare Instant
SlideShare InstantSlideShare Instant
SlideShare Instant
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Goodparts
GoodpartsGoodparts
Goodparts
 
Migration testing framework
Migration testing frameworkMigration testing framework
Migration testing framework
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rules
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 

Recently uploaded

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

JavaScript Needn't Hurt!

  • 1. JavaScript Needn’t Hurt! Thomas Kjeldahl Nilsson [email_address] linkedin.com/in/thomaskjeldahlnilsson twitter.com/thomanil
  • 3. Who Are You? Done any JavaScript? Dozen lines of code? Hundreds? Thousands?
  • 4. Who Am I? JavaScript enthusiast Hundreds of hours Thousands lines of code Not an expert!
  • 5. What Are We Covering Today? Language basics Html scripting Good practices Tools
  • 8.  
  • 11. A Note on ActionScript
  • 12. What Rocks? Powerful, elegant, dynamic Present & enabled for most users Not confined to the browser Small learning surface
  • 13. What Sucks? Rushed out the door Some bad language features Crossbrowser problems
  • 15. Language Basics Syntax Types Variables Objects Functions
  • 16. Basic Syntax Similar to Java, C# Operators, statements if-else, while, for, try-catch-finally Still in Kansas...
  • 17. Types Strings Numbers Booleans Objects Arrays
  • 18. Variable Declarations var x = “foo”; // string var x = 2; // number var x = true; // boolean var x = { }; // object var x = [ ]; // array
  • 20. Object Creation Literal Form var BasicProject = { name : &quot;Steria Workshop&quot;, version : 1.2, getName : function() { return this.name; } };
  • 21. Object Creation Dynamic Form var BasicProject = {}; BasicProject.name = &quot;Steria Workshop&quot;; BasicProject.version = 1.2; BasicProject.getName = function() { return this.name; };
  • 22. Objects as Maps (Associative Arrays) var Person = { firstname:&quot;John&quot;, lastname:&quot;Smith&quot; }; Person.firstname; // => &quot;John&quot; (Access using identifier) Person[&quot;firstname&quot;]; // => &quot;John&quot; (Access using variable name)
  • 23. Arrays are Special Case of Object var arr = []; // Always declared without size. // Grows as needed. arr[0] = true; arr[3] = &quot;john&quot;; arr[300] = { description : &quot;object!&quot; }; arr[100]; // => Undefined arr.length; // => 301
  • 24. Arrays and Objects Can Be Deeply Nested var OuterObject = { innerArray : [ innerObject : { deepestArray : [1,2,3] } ] };
  • 25. JSON {&quot;firstName&quot;:&quot;Gustav&quot;,&quot;lastName&quot;:&quot;Adolf&quot;, &quot;roles&quot;:[&quot;King of Sweden&quot;,&quot;Terrible shipbuilder&quot;], &quot;other&quot;:{&quot;birth&quot;:&quot;9.12.1594&quot;,&quot;death&quot;:&quot;16.11.1632&quot;}}
  • 26. Kind Familiar Looking { &quot;firstName&quot; : &quot;Gustav&quot;, &quot;lastName&quot; : &quot;Adolf&quot;, &quot;roles&quot; : [ &quot;King of Sweden&quot;, &quot;Terrible shipbuilder&quot; ], &quot;other&quot; : { &quot;birth&quot; : &quot;9.12.1594&quot;, &quot;death&quot; : &quot;16.11.1632&quot; } }
  • 27. JavaScript Object Literal! var EvaluatedObject = { firstName : &quot;Gustav&quot;, lastName : &quot;Adolf&quot;, roles : [ &quot;King of Sweden&quot;, &quot;Terrible shipbuilder&quot; ], other : { birth : &quot;9.12.1594&quot;, death : &quot;16.11.1632&quot; } } ;
  • 29. Prototypal Inheritance (Simplified) var Employee = {name : &quot;CEO Jack&quot;, company : &quot;ACME Inc.&quot;}; var Janitor = Object.create(Employee); // Janitor now looks and behaves just like its prototype, Employee Janitor.company // => &quot;ACME Inc.&quot;, falls back to prototype.company Janitor.name = &quot;Janitor Tim&quot;; // Override name Janitor.tools = [&quot;broom&quot;, &quot;bucket&quot;]; // Define member variable only on child Employee.name = &quot;CEO Jane&quot;; // Change name of prototype Janitor.name; // => Still &quot;Janitor Tim&quot;. Overriden members unaffected by prototype changes
  • 31. Simple Function Definition function add(a, b) { return a + b; }
  • 32. That's Just a Way of Saying: var add = function(a, b) { return a + b; }; // Use this consistently // Helps you remember: // Functions are just variables!
  • 33. An Anonymous Function... function(element) { // Do something with element }
  • 34. ...Can Be Sent To Another Function each(collection, function(element) { // Do something with current element });
  • 35. Example: Event Handler button.onClick(function(element) { alert(«You clicked me!»); });
  • 36. Sharp Edges Global variables No block s cope Semicolon insertion == operator
  • 37. Properly Scoped Variable var getSmallNumber = function(){ var smallNumber = 42; // Note use of var keyword return smallNumber; };
  • 38. Sloppy, Global Variable var getSmallNumber = function(){ smallNumber = 42; return smallNumber; }; // Missing var prefix = smallNumber gets global scope // Becomes available for all code // Sticks around and pollutes namespace
  • 39. No Block Scope var x = 1; if (true) { var x = 123; } // x => 123
  • 40. Semicolon insertion Don't force the browser to guess!
  • 41. Example a = b + c (d + e).print() becomes... a = b + c(d + e).print();
  • 43. Quiz '' == '0' // true or false? 0 == '' // true or false? 0 == '0' // true or false? false == 'false' // true or false? false == '0' // true or false? false == undefined // true or false? false == null // true or false? null == undefined // true or false? ' ' == 0 // true or false?
  • 44. How Many Did You Get? '' == '0' // false 0 == '' // true 0 == '0' // true false == 'false' // false false == '0' // true false == undefined // false false == null // false null == undefined // true ' ' == 0 // true // Why? Type coercion on right operand, that's why.
  • 45. Instead, Use === (And !==) '' === '0' // false 0 === '' // false 0 === '0' // false false === 'false' // false false === '0' // false false === undefined // false false === null // false null === undefined // false ' ' === 0 // false
  • 46. Advanced Stuff Closures Modules Memoization
  • 50.  
  • 51. <TABLE> <TBODY> <TR> <TD>Shady Grove</TD> <TD>Aeolian</TD> </TR> <TR> <TD>Over the River, Charlie</TD> <TD>Dorian</TD> </TR> </TBODY> </TABLE>
  • 52.  
  • 53. DOM Scripting Basics x.getElementById(id) ; // get the element with a specified id x.getElementsByTagName(name); // get all elements with a // specified tag name x.appendChild(node); // insert a child node to x x.removeChild(node), // remove a child node from x x.innerHTML = «<p>New text</p>»; // fill element with html or text
  • 55. DOM Api: Crossbrowser Headache http://www.quirksmode.org
  • 56. So Use a Framework!
  • 58. Instant Win: Crossbrowser Non-verbose Traverse DOM Manipulate DOM
  • 59. Lots of Other Stuff, Too Server communication UI widgets and effects each(), map(), etc JSON parsing +++
  • 60. jQuery Function $() // Short form jQuery() // Long form
  • 61. Find Stuff $(“p”); // Find all paragraphs $(“#shoppingList”); // Find element with id 'shoppingList' $(“.shoppingListItem”); // Find elements with class 'shoppingListItem' $(“:text”); // Find all text elements $(“:visible”); // Find only visible elements
  • 62. $() Wraps and Returns Matching Element(s)
  • 63. Manipulate Matched DOM Elements $(“p”).css(”color”, ”green”); // Set color on all paragraph elements $(“p”).hide(); // Hide all paragraphs // Make all input buttons react to mouse clicks $(“input”).click(function(){ alert(”You clicked this button!”); });
  • 64. Chaining Every API call returns jQuery object So we can chain function calls together “Fluent API”
  • 65. Chaining Example // Set color on all paragraph elements, then hide them all $(“p”).css(”color”, ”green”).hide();
  • 68. Caution! Use frameworks as needed But don't depend on them! JavaScript != jQuery
  • 69. Good Practices jsLint Automated testing Unobtrusive JavaScript
  • 72. Unobtrusive JavaScript Structure vs behavior Separate js files Event handler setup Namespaces Universal Access
  • 73.  
  • 74.  
  • 75.  
  • 76.  
  • 77.  
  • 78. Namespace Hygiene All your code within single object
  • 79. Universal Access Can all your users use your site? Users without JS? Blind users with screen readers? Use progressive enhancement
  • 80. Crossbrowser Dev Process Frameworks > raw DOM Test early, test often Clean, disciplined code
  • 83. What Did We Cover Today? Language basics Html scripting Good practices Tools
  • 84. What´s Missing? Server Communication Performance Security Practice practice practice!
  • 86.  
  • 87.  
  • 88. Web Resources http://javascript.crockford.com http://cjohansen.no/javascript http://developer.yahoo.com/yui/theater http://ajaxian.com
  • 89. Best Way to Learn: Start Building! http://ajaxian.com/archives/writing-a-javascript-tetris-lessons-learned-from-a-ruby-chap
  • 90. Download This Workshop http://kjeldahlnilsson.net/jsnh.zip Slides, lecture notes, exercises Creative Commons license Use and distribute freely... ...or have me present it for you on-site :)
  • 92. Contact Info [email_address] linkedin.com/in/thomaskjeldahlnilsson twitter.com/thomanil

Editor's Notes

  1. First page
  2. First page