SlideShare a Scribd company logo
1 of 27
Download to read offline
JavaScript From Scratch
       “Playing With Data”
Agenda

• Strings
• Numbers
• Booleans
• Arrays
• Objects
Strings

• Any data surrounded by quotes
 • ‘Single quotes’
 • “Double quotes”
• Usually things with non-numeric characters
Strings
   • Can be concatenated via the + operator
var name     = ‘Mike ’ + ‘Girouard’;
var sentence = name + ‘ is awesome!’;
var element = ‘p’;
var content = ‘Hello, world!’;
var tag     = ‘<’ + element + ‘>’;

tag = tag + content;
tag = tag + ‘</’ + element + ‘>’;
var element = ‘p’;
var content = ‘Hello, world!’;
var tag     = ‘<’ + element + ‘>’;

tag += content;
tag += ‘</’ + element + ‘>’;
Numbers

• Any kind of number
 • 1, 2, 4, 100, 79812     (Integers)

 • 1.2, 7.9, 1.2489, 1.0   (Floats)
var   product    =   ‘Widget’;
var   price      =   1.99;
var   quantity   =   4;
var   taxRate    =   .08375;

var subTotal = price * quantity;
var taxAmt   = subTotal * taxRate;
var total    = subTotal + taxAmt;
Booleans
• True/False values
var canDrink          = true;
var canParkInBrooklyn = false;
var isOver21    = (2008 - 1983) > 21;
var isEmpty     = (input.value == ‘’);
var isIEorOpera = (‘all’ in document);
if (isOver21) {
  alert(‘99 beers on the wall...’);
}
if (isEmpty) {
  alert(‘You missed something...’);
  input.focus();
}
if (isIEorOpera) {
  var url = ‘http://getfirefox.com/’;
  window.location = url;
}
var validLogin = (user == ‘foo’ &&
                  pass == ‘bar’);

if (!validLogin) {
  window.location = ‘bad-login.php’;
}
Arrays

• One variable, multiple values
• Use numbers to identify values
• Think about an <ol> in XHTML
 • ... that starts with 0
var colors = [‘red’, ‘green’, ‘blue’];

alert(colors[0]);
alert(colors[1]);
alert(colors[2]);
var sentence = ‘There are ’ +
  colors.length + ‘ colors total’;

colors.push(‘chartreuse’);

sentence = ‘Now there are ’ +
  colors.length;
Objects


• Like arrays: one variable, multiple values
• Instead of numbers, objects use strings
var birthdays = {
   ‘Mike’ : ‘01-14-83’,
   ‘John’ : ‘06-23-74’,
   ‘Amy’ : null
};

alert(birthdays.Mike);
alert(birthdays.John);
alert(birthdays.Amy);
Review

• Strings:
 • Begin and end with quotes
 • Quotes can be ‘single’ or “double”
 • Concatenated with a + operator
 • Appended with a += operator
Review

• Numbers:
 • Any kind of numeric data
 • Quotes are not necessary
Review

• Booleans:
 • true or false values
 • Form the basis of all logic in programming
 • Can be negated with a ! operator
Review

• Arrays:
 • One variable, multiple values
 • Indexed by numbers
   • ... beginning with 0
 • New items can be added with push()
Review

• Objects:
 • One variable, multiple values
 • Indexed by strings
Homework

• Build a micro-library for HTML generation
• Functions should accept arguments for
  each attribute
• Functions should return strings as a result
Homework

• Required Functions:
 • a (href, title, content)
 • img (src, alt)
 • p, h1 ... h6 (content)
Homework

• Required Functions:
 • ol, ul (listItems)
 • dl (dictionary)

More Related Content

Similar to JavaScript From Scratch: Playing With Data

WindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミングWindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミング
Yosuke HASEGAWA
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
2 coding101 fewd_lesson2_programming_overview 20210105
2 coding101 fewd_lesson2_programming_overview 202101052 coding101 fewd_lesson2_programming_overview 20210105
2 coding101 fewd_lesson2_programming_overview 20210105
John Picasso
 
Conditionals, basic list manipulation and pattern matching
Conditionals, basic list manipulation and pattern matchingConditionals, basic list manipulation and pattern matching
Conditionals, basic list manipulation and pattern matching
Rich Price
 

Similar to JavaScript From Scratch: Playing With Data (20)

Javascript
JavascriptJavascript
Javascript
 
Maintainable JavaScript
Maintainable JavaScriptMaintainable JavaScript
Maintainable JavaScript
 
Stop Programming in JavaScript By Luck
Stop Programming in JavaScript By LuckStop Programming in JavaScript By Luck
Stop Programming in JavaScript By Luck
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
JSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael Greifeneder
 
JavaScript from Scratch: Getting Your Feet Wet
JavaScript from Scratch: Getting Your Feet WetJavaScript from Scratch: Getting Your Feet Wet
JavaScript from Scratch: Getting Your Feet Wet
 
Introduction to Programming @ NTHUEEECamp 2015
Introduction to Programming @ NTHUEEECamp 2015Introduction to Programming @ NTHUEEECamp 2015
Introduction to Programming @ NTHUEEECamp 2015
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
WindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミングWindowsユーザのためのはじめてのPerlプログラミング
WindowsユーザのためのはじめてのPerlプログラミング
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the type
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Effective C#
Effective C#Effective C#
Effective C#
 
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
2 coding101 fewd_lesson2_programming_overview 20210105
2 coding101 fewd_lesson2_programming_overview 202101052 coding101 fewd_lesson2_programming_overview 20210105
2 coding101 fewd_lesson2_programming_overview 20210105
 
Conditionals, basic list manipulation and pattern matching
Conditionals, basic list manipulation and pattern matchingConditionals, basic list manipulation and pattern matching
Conditionals, basic list manipulation and pattern matching
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
CSIS 138 Javascript Class1
CSIS 138 Javascript Class1CSIS 138 Javascript Class1
CSIS 138 Javascript Class1
 

More from Michael Girouard

JavaScript From Scratch: Writing Java Script Applications
JavaScript From Scratch: Writing Java Script ApplicationsJavaScript From Scratch: Writing Java Script Applications
JavaScript From Scratch: Writing Java Script Applications
Michael Girouard
 
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
Michael Girouard
 
Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5
Michael Girouard
 
Learning To Love Java Script
Learning To Love Java ScriptLearning To Love Java Script
Learning To Love Java Script
Michael Girouard
 
Learning To Love Java Script Color
Learning To Love Java Script ColorLearning To Love Java Script Color
Learning To Love Java Script Color
Michael Girouard
 

More from Michael Girouard (16)

Day to Day Realities of an Independent Worker
Day to Day Realities of an Independent WorkerDay to Day Realities of an Independent Worker
Day to Day Realities of an Independent Worker
 
Responsible JavaScript
Responsible JavaScriptResponsible JavaScript
Responsible JavaScript
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Ajax for PHP Developers
Ajax for PHP DevelopersAjax for PHP Developers
Ajax for PHP Developers
 
JavaScript From Scratch: Writing Java Script Applications
JavaScript From Scratch: Writing Java Script ApplicationsJavaScript From Scratch: Writing Java Script Applications
JavaScript From Scratch: Writing Java Script Applications
 
JavaScript From Scratch: Events
JavaScript From Scratch: EventsJavaScript From Scratch: Events
JavaScript From Scratch: Events
 
Its More Than Just Markup
Its More Than Just MarkupIts More Than Just Markup
Its More Than Just Markup
 
Web Standards Evangelism
Web Standards EvangelismWeb Standards Evangelism
Web Standards Evangelism
 
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
 
A Look At Flex And Php
A Look At Flex And PhpA Look At Flex And Php
A Look At Flex And Php
 
Baking Cakes With Php
Baking Cakes With PhpBaking Cakes With Php
Baking Cakes With Php
 
Cfphp Zce 01 Basics
Cfphp Zce 01 BasicsCfphp Zce 01 Basics
Cfphp Zce 01 Basics
 
Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5
 
Learning To Love Java Script
Learning To Love Java ScriptLearning To Love Java Script
Learning To Love Java Script
 
Learning To Love Java Script Color
Learning To Love Java Script ColorLearning To Love Java Script Color
Learning To Love Java Script Color
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 

JavaScript From Scratch: Playing With Data

  • 1. JavaScript From Scratch “Playing With Data”
  • 2. Agenda • Strings • Numbers • Booleans • Arrays • Objects
  • 3. Strings • Any data surrounded by quotes • ‘Single quotes’ • “Double quotes” • Usually things with non-numeric characters
  • 4. Strings • Can be concatenated via the + operator var name = ‘Mike ’ + ‘Girouard’; var sentence = name + ‘ is awesome!’;
  • 5. var element = ‘p’; var content = ‘Hello, world!’; var tag = ‘<’ + element + ‘>’; tag = tag + content; tag = tag + ‘</’ + element + ‘>’;
  • 6. var element = ‘p’; var content = ‘Hello, world!’; var tag = ‘<’ + element + ‘>’; tag += content; tag += ‘</’ + element + ‘>’;
  • 7. Numbers • Any kind of number • 1, 2, 4, 100, 79812 (Integers) • 1.2, 7.9, 1.2489, 1.0 (Floats)
  • 8. var product = ‘Widget’; var price = 1.99; var quantity = 4; var taxRate = .08375; var subTotal = price * quantity; var taxAmt = subTotal * taxRate; var total = subTotal + taxAmt;
  • 9. Booleans • True/False values var canDrink = true; var canParkInBrooklyn = false;
  • 10. var isOver21 = (2008 - 1983) > 21; var isEmpty = (input.value == ‘’); var isIEorOpera = (‘all’ in document);
  • 11. if (isOver21) { alert(‘99 beers on the wall...’); }
  • 12. if (isEmpty) { alert(‘You missed something...’); input.focus(); }
  • 13. if (isIEorOpera) { var url = ‘http://getfirefox.com/’; window.location = url; }
  • 14. var validLogin = (user == ‘foo’ && pass == ‘bar’); if (!validLogin) { window.location = ‘bad-login.php’; }
  • 15. Arrays • One variable, multiple values • Use numbers to identify values • Think about an <ol> in XHTML • ... that starts with 0
  • 16. var colors = [‘red’, ‘green’, ‘blue’]; alert(colors[0]); alert(colors[1]); alert(colors[2]);
  • 17. var sentence = ‘There are ’ + colors.length + ‘ colors total’; colors.push(‘chartreuse’); sentence = ‘Now there are ’ + colors.length;
  • 18. Objects • Like arrays: one variable, multiple values • Instead of numbers, objects use strings
  • 19. var birthdays = { ‘Mike’ : ‘01-14-83’, ‘John’ : ‘06-23-74’, ‘Amy’ : null }; alert(birthdays.Mike); alert(birthdays.John); alert(birthdays.Amy);
  • 20. Review • Strings: • Begin and end with quotes • Quotes can be ‘single’ or “double” • Concatenated with a + operator • Appended with a += operator
  • 21. Review • Numbers: • Any kind of numeric data • Quotes are not necessary
  • 22. Review • Booleans: • true or false values • Form the basis of all logic in programming • Can be negated with a ! operator
  • 23. Review • Arrays: • One variable, multiple values • Indexed by numbers • ... beginning with 0 • New items can be added with push()
  • 24. Review • Objects: • One variable, multiple values • Indexed by strings
  • 25. Homework • Build a micro-library for HTML generation • Functions should accept arguments for each attribute • Functions should return strings as a result
  • 26. Homework • Required Functions: • a (href, title, content) • img (src, alt) • p, h1 ... h6 (content)
  • 27. Homework • Required Functions: • ol, ul (listItems) • dl (dictionary)