SlideShare a Scribd company logo
1 of 63
Download to read offline
Introduction to JavaScript
  Learn how to program your computer!
0
  You can and must
understand computers
        NOW
“ Everything is deeply intertwingled. In an
  important sense there are no “subjects” at all;
 there is only all knowledge, since the cross-
 connections among the myriad topics of this
 world simply cannot be divided up neatly.”

 —Ted Nelson, Computer Lib/Dream Machines
“ When human beings acquired language, we
learned not just how to listen but how to speak.
When we gained literacy, we learned not just how
to read but how to write. And as we move into an
increasingly digital reality, we must learn not just
how to use programs but how to make them.”

—Douglas Rushkoff, Program or Be Programmed
“ The single most significant change in the politics
  of cyberspace is the coming of age of this simple
 idea: The code is law. The architectures of
 cyberspace are as important as the law in defining
 and defeating the liberties of the Net.”

 —Lawrence Lessig, The Code Is the Law
1
Learning a new language
Code is text
Programming is
    typing
Programming is very
   careful typing
Programming is
  fast typing
Programming is
figuring out why it
       broke
Programming in general

• A series of text files that get compiled
  and executed

• Code is “digested,” going from human-
  readable to a hardware-ready form

• Ultimately programs run as assembly,
  low-level instructions for your CPU
JavaScript in particular

• Increasingly the web page scripting
  language

• Most likely the widest deployed
  runtime

• JavaScript has nothing to do with
  Java, except some syntax similarities
Lines of code


• A line of code is a basic unit of
  programming

• Tells the computer to do something
• Sometimes a “line” of code can span
  more than one line
A simple line of code

alert("Hello, world!");
Let’s try this using
      Firebug
2
Writing code
Compilers are unforgiving

• The computer cuts you no slack
• All code is subject to bugs
• The error console is your friend
• Debugging is about identifying,
  characterizing, and resolving
  problems
A simple line of code

    alert("Hello, world!");

Function name
A simple line of code

     alert("Hello, world!");

Function name Parentheses call the function
A simple line of code

     alert("Hello, world!");

Function name Parentheses call the function

                        Function argument (a string)
A simple line of code

     alert("Hello, world!");

Function name Parentheses call the function

                        Function argument (a string)

                                    Designates the end of the line
3
Variables
The variable metaphor



     “Variables are like a box
      you can put data into.”
The variable metaphor
The variable metaphor
Variables


• Variables store data for future use
• var x = y; is how you assign a new
  variable in JavaScript

• We can now refer to x in future lines
  of code, and know it means y
Variables (boolean type)


• Variables store data for future use
• var x = true; is how you assign a new
  variable in JavaScript

• We can now refer to x in future lines
  of code, and know it means true
Variables (boolean type)


• Variables store data for future use
• var x = false; is how you assign a new
  variable in JavaScript

• We can now refer to x in future lines
  of code, and know it means false
Variables (numeric type)


• Variables store data for future use
• var x = 47; is how you assign a new
  variable in JavaScript

• We can now refer to x in future lines
  of code, and know it means 47
Variables (string type)


• Variables store data for future use
• var x = "pony"; is how you assign a
  new variable in JavaScript

• We can now refer to x in future lines
  of code, and know it means pony.
Variable logic


// What   is the value of z?
var x =   3;
var y =   x + 1;
var z =   y;
4
Functions
Multiple lines of code



var msg = "Hello, world!";
var func = alert;
func(msg);

                    Designate the ends of the lines
Multiple lines of code



var msg = "Hello, world!";
var func = alert;
func(msg);



The first line stores a string
Multiple lines of code



var msg = "Hello, world!";
var func = alert;
func(msg);



The second line stores a function
Multiple lines of code



var msg = "Hello, world!";
var func = alert;
func(msg);



The third line executes the
stored function with the string
Commenting code

// First we store the message
var msg = "Hello, world!";

// Next, we choose a function to call
var func = alert;

// Finally, we combine the two
func(msg);
Commenting code

/*

This code demonstrates the standard
Hello World program, over three lines
instead of just one.

*/
var msg = "Hello, world!";
var func = alert;
func(msg);
Creating a new function

// Outputs a simple message
function output_message() {
  var msg = "Hello, world!";
  var func = alert;
  func(msg);
}
Calling our function

// Outputs a simple message
function output_message() {
  var msg = "Hello, world!";
  var func = alert;
  func(msg);
}

output_message();
Arguments

// Outputs a simple message
function output_message(msg) {
  var func = alert;
  func(msg);
}

output_message("Hello, world!");
output_message("¡Hola, mundo!");
5
Libraries
JavaScript on the web


<script>

// JavaScript code is typically embedded in HTML
// <script> tags

</script>
HTML + JavaScript
<html>
  <head>
    <title>HTML + JavaScript</title>
  </head>
  <body>
    <p>Stuff *on* the page goes up here.</p>
    <script>

    // JavaScript code that modifies the page should
    // go below everything else in the <body>.

    </script>
  </body>
</html>
Hide content
<html>
  <head>
    <title>Hide content</title>
  </head>
  <body>
    <p id="hide">Click to hide me!</p>
    <script src="mootools.js"></script>
    <script>
    $('hide').addEvent('click', function() {
       $('hide').fade('out');
    });
    </script>
  </body>
</html>
HTML + CSS + JavaScript
<html>
  <head>
    <title>HTML + CSS + JavaScript</title>
    <style>
    #content {
       background: #000;
    }
    </style>
  </head>
  <body>
    <p id="content">Hello, world!</p>
    <script>
      var content = document.getElementById('content');
       content.style.color = '#fff';
    </script>
  </body>
</html>
HTML + CSS + JavaScript

<html>
  <head>
    <title>HTML + CSS + JavaScript</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <p>
       Separating code into .js and .css files is a
       good way to keep things tidy.
    </p>
    <script src="scripts.js"></script>
  </body>
</html>
6
Slide show
Slide show HTML
<html>
  <head>
    <title>Slide show</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <div id="slides">
       <div id="inner">
         <img src="images/1.jpg" />
         <img src="images/2.jpg" />
         <img src="images/3.jpg" />
         <img src="images/4.jpg" />
       </div>
    </div>
    <script src="mootools.js"></script>
    <script src="script.js"></script>
  </body>
</html>
Slide show CSS
#slides {
  width: 991px;
  height: 671px;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
}

#inner {
  position: absolute;
  left: 0;
  top: 0;
}

#slides img {
  float: left;
}
Slide show JavaScript


var width = 991;
var n = 0;
var count = $$('#slides img').length;

$('slides').addEvent('click', function() {
  n = (n + 1) % count; // Increment
  $('inner').tween('left', n * -width);
});
7
What next?
Come up with a
   project
Try to build it
   yourself
Take your time, it
won’t come quickly
Resources
•   Eloquent JavaScript   •   _why’s poignant
                              guide to Ruby
•   MooTorial
                          •   Dive into Python
•   w3schools.com
                          •   Visual Quickstart
•   Mozilla devmo             Guide

•   WebMonkey             •   Lynda tutorials

•   The Rhino Book
http://www.vimeo.com/5047563
http://www.vimeo.com/5047563

More Related Content

What's hot

JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - IntroductionKwangshin Oh
 
Ruby On Rails Intro
Ruby On Rails IntroRuby On Rails Intro
Ruby On Rails IntroSarah Allen
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by BonnyBonny Chacko
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?daoswald
 
Introducing ruby on rails
Introducing ruby on railsIntroducing ruby on rails
Introducing ruby on railsPriceen
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
Javascript 2009
Javascript 2009Javascript 2009
Javascript 2009borkweb
 

What's hot (20)

Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - Introduction
 
Ruby On Rails Intro
Ruby On Rails IntroRuby On Rails Intro
Ruby On Rails Intro
 
Ruby
RubyRuby
Ruby
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
JavaScript Basics with baby steps
JavaScript Basics with baby stepsJavaScript Basics with baby steps
JavaScript Basics with baby steps
 
Welcome to hack
Welcome to hackWelcome to hack
Welcome to hack
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
 
Introducing ruby on rails
Introducing ruby on railsIntroducing ruby on rails
Introducing ruby on rails
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Ppt php
Ppt phpPpt php
Ppt php
 
Php converted pdf
Php converted pdfPhp converted pdf
Php converted pdf
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
Javascript 2009
Javascript 2009Javascript 2009
Javascript 2009
 
JavaScript
JavaScriptJavaScript
JavaScript
 

Viewers also liked

Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptKevin Ball
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptYakov Fain
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1Tomislav Capan
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptAnjan Banda
 
Introduction to javascript
Introduction to javascriptIntroduction to javascript
Introduction to javascriptSyd Lawrence
 
JavaScript Intro
JavaScript IntroJavaScript Intro
JavaScript IntroEric Brown
 
Javascript Intro 01
Javascript Intro 01Javascript Intro 01
Javascript Intro 01vikram singh
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web developmentAlberto Apellidos
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQueryShawn Calvert
 
Front end development best practices
Front end development best practicesFront end development best practices
Front end development best practicesKarolina Coates
 

Viewers also liked (20)

Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
JavaScript - Intro
JavaScript - IntroJavaScript - Intro
JavaScript - Intro
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1NodeJs Intro - JavaScript Zagreb Meetup #1
NodeJs Intro - JavaScript Zagreb Meetup #1
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Intro to javascript (4 week)
Intro to javascript (4 week)Intro to javascript (4 week)
Intro to javascript (4 week)
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Java Script Introduction
Java Script IntroductionJava Script Introduction
Java Script Introduction
 
Introduction to javascript
Introduction to javascriptIntroduction to javascript
Introduction to javascript
 
Javascript intro for MAH
Javascript intro for MAHJavascript intro for MAH
Javascript intro for MAH
 
JavaScript Intro
JavaScript IntroJavaScript Intro
JavaScript Intro
 
Web Design
Web DesignWeb Design
Web Design
 
Javascript Intro 01
Javascript Intro 01Javascript Intro 01
Javascript Intro 01
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web development
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQuery
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Intro to HTML
Intro to HTMLIntro to HTML
Intro to HTML
 
Front end development best practices
Front end development best practicesFront end development best practices
Front end development best practices
 

Similar to Intro to JavaScript

An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONSyed Moosa Kaleem
 
Leveling Up at JavaScript
Leveling Up at JavaScriptLeveling Up at JavaScript
Leveling Up at JavaScriptRaymond Camden
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMarlon Jamera
 
JavaScript : A trending scripting language
JavaScript : A trending scripting languageJavaScript : A trending scripting language
JavaScript : A trending scripting languageAbhayDhupar
 
Enterprise JavaScript ... what the heck?
Enterprise JavaScript ... what the heck?Enterprise JavaScript ... what the heck?
Enterprise JavaScript ... what the heck?Nedelcho Delchev
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java scriptnanjil1984
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersMohammed Mushtaq Ahmed
 
Journey To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The MachineJourney To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The MachineIrfan Maulana
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptxMattMarino13
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 

Similar to Intro to JavaScript (20)

An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Leveling Up at JavaScript
Leveling Up at JavaScriptLeveling Up at JavaScript
Leveling Up at JavaScript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JavaScript : A trending scripting language
JavaScript : A trending scripting languageJavaScript : A trending scripting language
JavaScript : A trending scripting language
 
Java script
Java scriptJava script
Java script
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Enterprise JavaScript ... what the heck?
Enterprise JavaScript ... what the heck?Enterprise JavaScript ... what the heck?
Enterprise JavaScript ... what the heck?
 
js.pptx
js.pptxjs.pptx
js.pptx
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
All of javascript
All of javascriptAll of javascript
All of javascript
 
Journey To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The MachineJourney To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The Machine
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 

More from Dan Phiffer

Static layouts with css
Static layouts with cssStatic layouts with css
Static layouts with cssDan Phiffer
 
Word press templates
Word press templatesWord press templates
Word press templatesDan Phiffer
 
Intro to word press
Intro to word pressIntro to word press
Intro to word pressDan Phiffer
 

More from Dan Phiffer (7)

Occupy.here
Occupy.hereOccupy.here
Occupy.here
 
Static layouts with css
Static layouts with cssStatic layouts with css
Static layouts with css
 
Word press templates
Word press templatesWord press templates
Word press templates
 
Intro to word press
Intro to word pressIntro to word press
Intro to word press
 
Diving into php
Diving into phpDiving into php
Diving into php
 
The web context
The web contextThe web context
The web context
 
Web tech 101
Web tech 101Web tech 101
Web tech 101
 

Recently uploaded

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Intro to JavaScript

  • 1. Introduction to JavaScript Learn how to program your computer!
  • 2. 0 You can and must understand computers NOW
  • 3. “ Everything is deeply intertwingled. In an important sense there are no “subjects” at all; there is only all knowledge, since the cross- connections among the myriad topics of this world simply cannot be divided up neatly.” —Ted Nelson, Computer Lib/Dream Machines
  • 4. “ When human beings acquired language, we learned not just how to listen but how to speak. When we gained literacy, we learned not just how to read but how to write. And as we move into an increasingly digital reality, we must learn not just how to use programs but how to make them.” —Douglas Rushkoff, Program or Be Programmed
  • 5. “ The single most significant change in the politics of cyberspace is the coming of age of this simple idea: The code is law. The architectures of cyberspace are as important as the law in defining and defeating the liberties of the Net.” —Lawrence Lessig, The Code Is the Law
  • 6. 1 Learning a new language
  • 8. Programming is typing
  • 9. Programming is very careful typing
  • 10. Programming is fast typing
  • 12. Programming in general • A series of text files that get compiled and executed • Code is “digested,” going from human- readable to a hardware-ready form • Ultimately programs run as assembly, low-level instructions for your CPU
  • 13. JavaScript in particular • Increasingly the web page scripting language • Most likely the widest deployed runtime • JavaScript has nothing to do with Java, except some syntax similarities
  • 14. Lines of code • A line of code is a basic unit of programming • Tells the computer to do something • Sometimes a “line” of code can span more than one line
  • 15. A simple line of code alert("Hello, world!");
  • 16. Let’s try this using Firebug
  • 18. Compilers are unforgiving • The computer cuts you no slack • All code is subject to bugs • The error console is your friend • Debugging is about identifying, characterizing, and resolving problems
  • 19.
  • 20.
  • 21.
  • 22. A simple line of code alert("Hello, world!"); Function name
  • 23. A simple line of code alert("Hello, world!"); Function name Parentheses call the function
  • 24. A simple line of code alert("Hello, world!"); Function name Parentheses call the function Function argument (a string)
  • 25. A simple line of code alert("Hello, world!"); Function name Parentheses call the function Function argument (a string) Designates the end of the line
  • 27. The variable metaphor “Variables are like a box you can put data into.”
  • 30. Variables • Variables store data for future use • var x = y; is how you assign a new variable in JavaScript • We can now refer to x in future lines of code, and know it means y
  • 31. Variables (boolean type) • Variables store data for future use • var x = true; is how you assign a new variable in JavaScript • We can now refer to x in future lines of code, and know it means true
  • 32. Variables (boolean type) • Variables store data for future use • var x = false; is how you assign a new variable in JavaScript • We can now refer to x in future lines of code, and know it means false
  • 33. Variables (numeric type) • Variables store data for future use • var x = 47; is how you assign a new variable in JavaScript • We can now refer to x in future lines of code, and know it means 47
  • 34. Variables (string type) • Variables store data for future use • var x = "pony"; is how you assign a new variable in JavaScript • We can now refer to x in future lines of code, and know it means pony.
  • 35. Variable logic // What is the value of z? var x = 3; var y = x + 1; var z = y;
  • 37. Multiple lines of code var msg = "Hello, world!"; var func = alert; func(msg); Designate the ends of the lines
  • 38. Multiple lines of code var msg = "Hello, world!"; var func = alert; func(msg); The first line stores a string
  • 39. Multiple lines of code var msg = "Hello, world!"; var func = alert; func(msg); The second line stores a function
  • 40. Multiple lines of code var msg = "Hello, world!"; var func = alert; func(msg); The third line executes the stored function with the string
  • 41. Commenting code // First we store the message var msg = "Hello, world!"; // Next, we choose a function to call var func = alert; // Finally, we combine the two func(msg);
  • 42. Commenting code /* This code demonstrates the standard Hello World program, over three lines instead of just one. */ var msg = "Hello, world!"; var func = alert; func(msg);
  • 43. Creating a new function // Outputs a simple message function output_message() { var msg = "Hello, world!"; var func = alert; func(msg); }
  • 44. Calling our function // Outputs a simple message function output_message() { var msg = "Hello, world!"; var func = alert; func(msg); } output_message();
  • 45. Arguments // Outputs a simple message function output_message(msg) { var func = alert; func(msg); } output_message("Hello, world!"); output_message("¡Hola, mundo!");
  • 47. JavaScript on the web <script> // JavaScript code is typically embedded in HTML // <script> tags </script>
  • 48. HTML + JavaScript <html> <head> <title>HTML + JavaScript</title> </head> <body> <p>Stuff *on* the page goes up here.</p> <script> // JavaScript code that modifies the page should // go below everything else in the <body>. </script> </body> </html>
  • 49. Hide content <html> <head> <title>Hide content</title> </head> <body> <p id="hide">Click to hide me!</p> <script src="mootools.js"></script> <script> $('hide').addEvent('click', function() { $('hide').fade('out'); }); </script> </body> </html>
  • 50. HTML + CSS + JavaScript <html> <head> <title>HTML + CSS + JavaScript</title> <style> #content { background: #000; } </style> </head> <body> <p id="content">Hello, world!</p> <script> var content = document.getElementById('content'); content.style.color = '#fff'; </script> </body> </html>
  • 51. HTML + CSS + JavaScript <html> <head> <title>HTML + CSS + JavaScript</title> <link rel="stylesheet" href="styles.css" /> </head> <body> <p> Separating code into .js and .css files is a good way to keep things tidy. </p> <script src="scripts.js"></script> </body> </html>
  • 53.
  • 54. Slide show HTML <html> <head> <title>Slide show</title> <link rel="stylesheet" href="styles.css" /> </head> <body> <div id="slides"> <div id="inner"> <img src="images/1.jpg" /> <img src="images/2.jpg" /> <img src="images/3.jpg" /> <img src="images/4.jpg" /> </div> </div> <script src="mootools.js"></script> <script src="script.js"></script> </body> </html>
  • 55. Slide show CSS #slides { width: 991px; height: 671px; margin: 0 auto; overflow: hidden; position: relative; } #inner { position: absolute; left: 0; top: 0; } #slides img { float: left; }
  • 56. Slide show JavaScript var width = 991; var n = 0; var count = $$('#slides img').length; $('slides').addEvent('click', function() { n = (n + 1) % count; // Increment $('inner').tween('left', n * -width); });
  • 58. Come up with a project
  • 59. Try to build it yourself
  • 60. Take your time, it won’t come quickly
  • 61. Resources • Eloquent JavaScript • _why’s poignant guide to Ruby • MooTorial • Dive into Python • w3schools.com • Visual Quickstart • Mozilla devmo Guide • WebMonkey • Lynda tutorials • The Rhino Book