SlideShare a Scribd company logo
JavaScript
 JavaScript – programming language that can
 appear in html pages.
 It allow us to:
   To dynamically create web pages
   To control a browser application
     Open and create new browser windows
     Download and display contents of any URL
   To interact with the user
   Ability to interact with HTML forms
     You can process values provided by checkbox, text, textarea
     buttons




                                                                   1
JavaScript
 What is not possible with JavaScript
   It is not possible to read and write files (security reasons)
   The only networking support it provides is:
      It can send the contents of forms to a server and e-mail
      addresses
      It can cause the browser to load a web page
 JavaScript is not Java, however …
   JavaScript program constructs are similar to Java’s
   constructs (in many cases identical)
   JavaScript can interact with java programs




                                                                   2
JavaScript
JavaScript Interpreter – Process javaScript code
To write JavaScript programs you need
   A web browser
   A text editor
A JavaScript program can appear
   In a file by itself typically named with the extension .js
   In html files between a <script> and </script> tags
Client-Side JavaScript – the result of embedding a JavaScript
interpreter in a web browser
Example1 (See Example1.html)
   We use document.writeln to create the page contents
   Notice the html tags present in the writeln




                                                                3
JavaScript
When learning JavaScript we can identify two main areas
   Core JavaScript – Set of rules specifying how to write JavaScript
   programs
   Client-Side JavaScript – How JavaScript is used in web browsers
A JavaScript program can appear
   In a file by itself in a file typically with the extension .js
   In html files between a <script> and </script> tags
Example1
   We use document.writeln to create the page contents
   Notice the html tags present in the writeln




                                                                       4
Embedding JavaScript in HTML
Different ways to embed JavaScript in HTML
  By using <script> and </script> tags in the html document
  From an external file (specified via URL) using the src
  attribute of the script tag
    <script src=“demo.js”></script>
    script src behaves as if contents of file appears directly
    between the tags
  As event handler
    Example2 (See Example2.html)
  JavaScript URLs
    javascript:alert(“Welcome”)




                                                                 5
<script> Embedding
You may place any number of JavaScript statements
between <script> and </script>
Statements are executed as the document is loaded
<script> may appear in the head or body section of an
html document
Several pairs of nonoverlapping <script></script> blocks
can appear in a document
  All are consider part of the same program
  If you define a value in a block it can be referred from another
  block




                                                                     6
<script> Embedding
language attribute (e.g., <script language=“JavaScript”></script>)
   JavaScript is not the only language out there
      Visual Basic Scripting Language (language = “VBScript”)
   IE and Netscape will assume JavaScript if language is not specified.
   The language attribute allows you to specify a JavaScript version to use
   (e.g., <script language=“JavaScript1.5”>
   If a browser doesn’t understand a language it will ignore the statements
type (e.g, <script type=“text/javascript”>
   HTML 4 deprecates the language attribute (although language is widely
   use) using instead the type attribute




                                                                              7
External File Embedding
Script src behaves as if contents of file appears directly
between the tags
Example3 (See Example3.html and footer.js)
The src specifies an URL as its value
Advantages of external file
  Simplifies html files by removing code file
  Allows you to share code among html files
  Improves efficiency by allowing the web browser to
  cache the code




                                                             8
Event Handlers Embedding
Dynamic interaction with a user is possible by
responding to events (e.g., when the user clicks on a
button)
Events – Originate from html objects (e.g. buttons)
Event Handler – What will take place when an Event
occurs
Event Handler defined as attribute of html object
  In Example 2 the handler is represented by the string (collection
  of characters) that follows the onclick
  alert(new Date()) represents a statement. Each statement must
  be separated by semicolons.
  When someone selects the button the code is executed.




                                                                      9
Execution of JavaScript
Programs
 HTML parser – Takes care of processing an html
 document
 JavaScript interpreter – Takes care of processing
 JavaScript code
 HTML parser – must stop processing an html file when
 JavaScript code is found (JavaScript interpreter will then
 be running)
   This implies a page with JavaScript code that is computationally
   intensive can take a long time to load




                                                                  10
JavaScript
 Let’s go over several basic constructs that allow us to define
 JavaScript programs.
 Some definitions
    string – Any set of characters in double quotes (“ “)
    function/method – An entity that completes a particular task for
    us. It can takes values necessary to complete the particular task
    and it can return values.
 Generating Output with the document.writeln method
    Allow us to add text to the html file (see Example1) by providing
    the required text in “ “
    You can specify html code and results of JavaScript constructs




                                                                    11
JavaScript (Output)
 Example 4 (See Example4.html)
   Illustrates how we can create a table using document.writeln
   Notice how we can use the Date() to specify a particular date
   format. Date() is part of JavaScript
   The + allow us to concatenate strings
   Notice how we have specified the border size. If you use “ “ then
   the table will not be generated. You need to use single quotes.
   Keep in mind that this example could have been written without
   using JavaScript. However you will see how by extending code
   similar to the one provided you can dynamically decide what your
   final html look like




                                                                   12
JavaScript (Variables )
 variable – A memory location that can store a value. In JavaScript
 variables are declared using var
     var name;
 Variables names must start with a letter and can be followed by
 letters and digits
 A variable can hold different type of values
 Values we can assign to variables
     Integer – 0, 10, 40, 6, -7
     Floating-point – 3.2, .67, 1.48E-20
     String literals – “hello”, “goodbye”
 Operators
     Typical arithmetic operators (+, -, *, /)
 Example 5 (See Example5.html)


                                                                      13
JavaScript (Dialog Boxes)
 We can perform input and output via dialog boxes
 Input via prompt, Example 6 (See Example6.html)
   Notice we can define several variables at the same
   time
 Comments
   Can be defined using // (Everything until end of the
   line is a comment)
   Can be defined using /* */ (Everything in between /*
   and */ is considered a comment.
   /* */ can span several lines (// don’t)



                                                          14
JavaScript References

  JavaScript The Definitive Guide by David
  Flanagan
  ISBN: 0-596-00048-0

  JavaScript Pocket Reference by David Flanagan
  ISBN: 0-596-00411-7




                                                  15

More Related Content

DOC
2javascript web programming with JAVA script
umardanjumamaiwada
 
PPTX
Java script
reddivarihareesh
 
PPTX
Jscript part1
Girish Srivastava
 
PPTX
Web-Dev Portfolio
nwbgh
 
PDF
INTRODUCTION TO CLIENT SIDE PROGRAMMING
Prof Ansari
 
PDF
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
PPTX
1. java script language fundamentals
Rajiv Gupta
 
PPTX
Introduction to JavaScript Programming
Raveendra R
 
2javascript web programming with JAVA script
umardanjumamaiwada
 
Java script
reddivarihareesh
 
Jscript part1
Girish Srivastava
 
Web-Dev Portfolio
nwbgh
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
Prof Ansari
 
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
1. java script language fundamentals
Rajiv Gupta
 
Introduction to JavaScript Programming
Raveendra R
 

What's hot (20)

PPTX
Javascript
Sun Technlogies
 
PDF
3. Java Script
Jalpesh Vasa
 
PPTX
Web programming
Leo Mark Villar
 
PPT
Learn javascript easy steps
prince Loffar
 
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
PPTX
Introduction to Javascript By Satyen
Satyen Pandya
 
PPTX
Javascript functions
Alaref Abushaala
 
PDF
Carlos Amador .Net Portfolio
CMA_SlideShare
 
PPTX
JavaScript with Syntax & Implementation
Soumen Santra
 
PDF
Basic JavaScript Tutorial
DHTMLExtreme
 
DOC
Basics java scripts
ch samaram
 
PPT
Javascript Basics
Vishal Mittal
 
RTF
Java scripts
Capgemini India
 
PPTX
Javascript
D V BHASKAR REDDY
 
PPTX
Javascript
Nagarajan
 
PDF
Javascript
Rajavel Dhandabani
 
PPT
Java script Learn Easy
prince Loffar
 
PPT
Java script
Fajar Baskoro
 
PPT
Java script -23jan2015
Sasidhar Kothuru
 
PPTX
Introduction to JavaScript
Marlon Jamera
 
Javascript
Sun Technlogies
 
3. Java Script
Jalpesh Vasa
 
Web programming
Leo Mark Villar
 
Learn javascript easy steps
prince Loffar
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
Introduction to Javascript By Satyen
Satyen Pandya
 
Javascript functions
Alaref Abushaala
 
Carlos Amador .Net Portfolio
CMA_SlideShare
 
JavaScript with Syntax & Implementation
Soumen Santra
 
Basic JavaScript Tutorial
DHTMLExtreme
 
Basics java scripts
ch samaram
 
Javascript Basics
Vishal Mittal
 
Java scripts
Capgemini India
 
Javascript
D V BHASKAR REDDY
 
Javascript
Nagarajan
 
Javascript
Rajavel Dhandabani
 
Java script Learn Easy
prince Loffar
 
Java script
Fajar Baskoro
 
Java script -23jan2015
Sasidhar Kothuru
 
Introduction to JavaScript
Marlon Jamera
 
Ad

Similar to Lect35 javascript (20)

PPTX
Java script
Sukrit Gupta
 
PPTX
Java script Basic
Jaya Kumari
 
PPTX
01 Introduction - JavaScript Development
Tommy Vercety
 
PPTX
HNDIT1022 Week 08, 09 10 Theory web .pptx
IsuriUmayangana
 
PDF
Lecture7
Majid Taghiloo
 
PPTX
Lecture 5 javascript
Mujtaba Haider
 
PDF
javascriptPresentation.pdf
wildcat9335
 
PPTX
JavaScript_III.pptx
rashmiisrani1
 
PDF
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
kavigamage62
 
PPT
JAVA SCRIPT
Go4Guru
 
PDF
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
PDF
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
PDF
WT UNIT 2 presentation :client side technologies JavaScript And Dom
SrushtiGhise
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PDF
4007655 introduction-to-javascript
Vikash Chandra
 
PPT
Java script
sanjay joshi
 
PPT
Java script
umesh patil
 
PPTX
Final Java-script.pptx
AlkanthiSomesh
 
PDF
JS BASICS JAVA SCRIPT SCRIPTING
Arulkumar
 
PPTX
Java script
Abhishek Kesharwani
 
Java script
Sukrit Gupta
 
Java script Basic
Jaya Kumari
 
01 Introduction - JavaScript Development
Tommy Vercety
 
HNDIT1022 Week 08, 09 10 Theory web .pptx
IsuriUmayangana
 
Lecture7
Majid Taghiloo
 
Lecture 5 javascript
Mujtaba Haider
 
javascriptPresentation.pdf
wildcat9335
 
JavaScript_III.pptx
rashmiisrani1
 
java-scriptcdvcx vnbm,azsdfghjkml;sxdfcgmndxfcgvhb nmfctgvbhjnm ,cfgvb nm,xc ...
kavigamage62
 
JAVA SCRIPT
Go4Guru
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
WT UNIT 2 presentation :client side technologies JavaScript And Dom
SrushtiGhise
 
Introduction to JavaScript
Andres Baravalle
 
4007655 introduction-to-javascript
Vikash Chandra
 
Java script
sanjay joshi
 
Java script
umesh patil
 
Final Java-script.pptx
AlkanthiSomesh
 
JS BASICS JAVA SCRIPT SCRIPTING
Arulkumar
 
Java script
Abhishek Kesharwani
 
Ad

Recently uploaded (20)

PPTX
Social Media Marketing for Business Growth
vidhi622006
 
PPTX
Mining Services and Iron Ore Transportation in India.pptx
Naaraayani Minerals Pvt.Ltd
 
PPTX
Foreign-Direct-Investment-Shaping-the-Global-Trade-Landscape 5.pptx
Blackworld7
 
DOCX
UNIT 2 BC.docx- cv - RESOLUTION -MINUTES-NOTICE - BUSINESS LETTER DRAFTING
MANJU N
 
PPTX
Virbyze_Our company profile_Preview.pptx
myckwabs
 
PPTX
Buy Chaos Software – V-Ray, Enscape & Vantage Licenses in India
PI Software
 
PDF
MDR Services – 24x7 Managed Detection and Response
CyberNX Technologies Private Limited
 
PPTX
Is Your Brand Ready for Expansion? A Strategic Guide to Scaling Successfully
RUPAL AGARWAL
 
PDF
Data Sheet Cloud Integration Platform - dataZap
Chainsys SEO
 
PDF
Danielle Oliveira New Jersey - A Seasoned Lieutenant
Danielle Oliveira New Jersey
 
PPTX
Keynote: CATHOLIC UNIVERSITY: A PLACE OF CREATIVITY AND KNOWLEDGE
Alvaro Barbosa
 
PDF
2025 07 29 The Future, Backwards Agile 2025.pdf
Daniel Walsh
 
PDF
Withum Webinar - OBBBA: Tax Insights for Food and Consumer Brands
Withum
 
PDF
Bihar Idea festival - Pitch deck-your story.pdf
roharamuk
 
PPTX
Financial Management for business management .pptx
Hasibullah Ahmadi
 
PDF
TriStar Gold Corporate Presentation August 2025
Adnet Communications
 
PDF
Unveiling the Latest Threat Intelligence Practical Strategies for Strengtheni...
Auxis Consulting & Outsourcing
 
PDF
Rodolfo Belcastro su All Around The Worlds Magazine - Febbraio 2025
Rodolfo Belcastro
 
DOCX
unit 1 BC.docx - INTRODUCTION TO BUSINESS COMMUICATION
MANJU N
 
PDF
Followers to Fees - Social media for Speakers
Corey Perlman, Social Media Speaker and Consultant
 
Social Media Marketing for Business Growth
vidhi622006
 
Mining Services and Iron Ore Transportation in India.pptx
Naaraayani Minerals Pvt.Ltd
 
Foreign-Direct-Investment-Shaping-the-Global-Trade-Landscape 5.pptx
Blackworld7
 
UNIT 2 BC.docx- cv - RESOLUTION -MINUTES-NOTICE - BUSINESS LETTER DRAFTING
MANJU N
 
Virbyze_Our company profile_Preview.pptx
myckwabs
 
Buy Chaos Software – V-Ray, Enscape & Vantage Licenses in India
PI Software
 
MDR Services – 24x7 Managed Detection and Response
CyberNX Technologies Private Limited
 
Is Your Brand Ready for Expansion? A Strategic Guide to Scaling Successfully
RUPAL AGARWAL
 
Data Sheet Cloud Integration Platform - dataZap
Chainsys SEO
 
Danielle Oliveira New Jersey - A Seasoned Lieutenant
Danielle Oliveira New Jersey
 
Keynote: CATHOLIC UNIVERSITY: A PLACE OF CREATIVITY AND KNOWLEDGE
Alvaro Barbosa
 
2025 07 29 The Future, Backwards Agile 2025.pdf
Daniel Walsh
 
Withum Webinar - OBBBA: Tax Insights for Food and Consumer Brands
Withum
 
Bihar Idea festival - Pitch deck-your story.pdf
roharamuk
 
Financial Management for business management .pptx
Hasibullah Ahmadi
 
TriStar Gold Corporate Presentation August 2025
Adnet Communications
 
Unveiling the Latest Threat Intelligence Practical Strategies for Strengtheni...
Auxis Consulting & Outsourcing
 
Rodolfo Belcastro su All Around The Worlds Magazine - Febbraio 2025
Rodolfo Belcastro
 
unit 1 BC.docx - INTRODUCTION TO BUSINESS COMMUICATION
MANJU N
 
Followers to Fees - Social media for Speakers
Corey Perlman, Social Media Speaker and Consultant
 

Lect35 javascript

  • 1. JavaScript JavaScript – programming language that can appear in html pages. It allow us to: To dynamically create web pages To control a browser application Open and create new browser windows Download and display contents of any URL To interact with the user Ability to interact with HTML forms You can process values provided by checkbox, text, textarea buttons 1
  • 2. JavaScript What is not possible with JavaScript It is not possible to read and write files (security reasons) The only networking support it provides is: It can send the contents of forms to a server and e-mail addresses It can cause the browser to load a web page JavaScript is not Java, however … JavaScript program constructs are similar to Java’s constructs (in many cases identical) JavaScript can interact with java programs 2
  • 3. JavaScript JavaScript Interpreter – Process javaScript code To write JavaScript programs you need A web browser A text editor A JavaScript program can appear In a file by itself typically named with the extension .js In html files between a <script> and </script> tags Client-Side JavaScript – the result of embedding a JavaScript interpreter in a web browser Example1 (See Example1.html) We use document.writeln to create the page contents Notice the html tags present in the writeln 3
  • 4. JavaScript When learning JavaScript we can identify two main areas Core JavaScript – Set of rules specifying how to write JavaScript programs Client-Side JavaScript – How JavaScript is used in web browsers A JavaScript program can appear In a file by itself in a file typically with the extension .js In html files between a <script> and </script> tags Example1 We use document.writeln to create the page contents Notice the html tags present in the writeln 4
  • 5. Embedding JavaScript in HTML Different ways to embed JavaScript in HTML By using <script> and </script> tags in the html document From an external file (specified via URL) using the src attribute of the script tag <script src=“demo.js”></script> script src behaves as if contents of file appears directly between the tags As event handler Example2 (See Example2.html) JavaScript URLs javascript:alert(“Welcome”) 5
  • 6. <script> Embedding You may place any number of JavaScript statements between <script> and </script> Statements are executed as the document is loaded <script> may appear in the head or body section of an html document Several pairs of nonoverlapping <script></script> blocks can appear in a document All are consider part of the same program If you define a value in a block it can be referred from another block 6
  • 7. <script> Embedding language attribute (e.g., <script language=“JavaScript”></script>) JavaScript is not the only language out there Visual Basic Scripting Language (language = “VBScript”) IE and Netscape will assume JavaScript if language is not specified. The language attribute allows you to specify a JavaScript version to use (e.g., <script language=“JavaScript1.5”> If a browser doesn’t understand a language it will ignore the statements type (e.g, <script type=“text/javascript”> HTML 4 deprecates the language attribute (although language is widely use) using instead the type attribute 7
  • 8. External File Embedding Script src behaves as if contents of file appears directly between the tags Example3 (See Example3.html and footer.js) The src specifies an URL as its value Advantages of external file Simplifies html files by removing code file Allows you to share code among html files Improves efficiency by allowing the web browser to cache the code 8
  • 9. Event Handlers Embedding Dynamic interaction with a user is possible by responding to events (e.g., when the user clicks on a button) Events – Originate from html objects (e.g. buttons) Event Handler – What will take place when an Event occurs Event Handler defined as attribute of html object In Example 2 the handler is represented by the string (collection of characters) that follows the onclick alert(new Date()) represents a statement. Each statement must be separated by semicolons. When someone selects the button the code is executed. 9
  • 10. Execution of JavaScript Programs HTML parser – Takes care of processing an html document JavaScript interpreter – Takes care of processing JavaScript code HTML parser – must stop processing an html file when JavaScript code is found (JavaScript interpreter will then be running) This implies a page with JavaScript code that is computationally intensive can take a long time to load 10
  • 11. JavaScript Let’s go over several basic constructs that allow us to define JavaScript programs. Some definitions string – Any set of characters in double quotes (“ “) function/method – An entity that completes a particular task for us. It can takes values necessary to complete the particular task and it can return values. Generating Output with the document.writeln method Allow us to add text to the html file (see Example1) by providing the required text in “ “ You can specify html code and results of JavaScript constructs 11
  • 12. JavaScript (Output) Example 4 (See Example4.html) Illustrates how we can create a table using document.writeln Notice how we can use the Date() to specify a particular date format. Date() is part of JavaScript The + allow us to concatenate strings Notice how we have specified the border size. If you use “ “ then the table will not be generated. You need to use single quotes. Keep in mind that this example could have been written without using JavaScript. However you will see how by extending code similar to the one provided you can dynamically decide what your final html look like 12
  • 13. JavaScript (Variables ) variable – A memory location that can store a value. In JavaScript variables are declared using var var name; Variables names must start with a letter and can be followed by letters and digits A variable can hold different type of values Values we can assign to variables Integer – 0, 10, 40, 6, -7 Floating-point – 3.2, .67, 1.48E-20 String literals – “hello”, “goodbye” Operators Typical arithmetic operators (+, -, *, /) Example 5 (See Example5.html) 13
  • 14. JavaScript (Dialog Boxes) We can perform input and output via dialog boxes Input via prompt, Example 6 (See Example6.html) Notice we can define several variables at the same time Comments Can be defined using // (Everything until end of the line is a comment) Can be defined using /* */ (Everything in between /* and */ is considered a comment. /* */ can span several lines (// don’t) 14
  • 15. JavaScript References JavaScript The Definitive Guide by David Flanagan ISBN: 0-596-00048-0 JavaScript Pocket Reference by David Flanagan ISBN: 0-596-00411-7 15