Chpter 3 - introduction to JavaScript.pptx - Chapter 3 Overview on JavaScript 2019 2011 EC [email protected] 1 Outline 2019 2011 EC [email protected] 2 Introduction to

Chpter 3 - introduction to JavaScript.pptx - Chapter 3...

This preview shows page 1 - 21 out of 51 pages.

Chapter 3 Chapter 3 Overview on JavaScript 2019 / 2011 EC [email protected] 1
Image of page 1
Outline 2019 / 2011 EC [email protected] 2
Image of page 2
3 Introduction to JavaScript What is JavaScript? It is designed to add interactivity to HTML pages It is a scripting language (a lightweight programming language) It is an interpreted language (it executes without preliminary compilation) Usually embedded directly into HTML pages And, Java and JavaScript are different
Image of page 3
4 What can a JavaScript Do? JavaScript gives HTML designers a programming tool: simple syntax JavaScript can put dynamic text into an HTML page JavaScript can react to events JavaScript can read and write HTML elements JavaScript can be used to validate data JavaScript can be used to detect the visitor’s browser JavaScript can be used to create cookies Store and retrieve information on the visitor’s computer
Image of page 4
5 JavaScript How To The HTML <script> tag is used to insert a JavaScript into an HTML page <script type=“text/javascript”> document.write(“Hello World!”) </script> Ending statements with a semicolon? Optional; required when you want to put multiple statements on a single line
Image of page 5
Placement JavaScript can be inserted within the head, the body, or use external JavaScript file Functions and code that may execute multiple times is typically placed in the <HEAD> These are only interpreted when the relevant function or event-handler are called If you need a script to run as the page loads so that the script generates content in the page, then the script goes in the <body> portion of the document 2019 / 2011 EC [email protected] 6
Image of page 6
Note that: JavaScripts are visible in the client browser Since they are typically acting only on the client, However, if we want to prevent the script itself from being (easily) seen, we can upload our JavaScript from a file This will show only the upload tag in our final document, not the JavaScript from the file Use the source option in the tag <script type="text/javascript" src="filename.js" ></script> 2019 / 2011 EC [email protected] 7
Image of page 7
Basic JavaScript Syntax
Image of page 8
Basic JavaScript Syntax Notice that there is no main() function/method
Image of page 9
Basic JavaScript Syntax Comments like Java/C++ (/* */ also allowed)
Image of page 10
Basic JavaScript Syntax Variable declarations: - Not required - Data type not specified
Image of page 11
Basic JavaScript Syntax Semi-colons are usually not required, but always allowed at statement end
Image of page 12
Basic JavaScript Syntax Arithmetic operators same as Java/C++
Image of page 13
Basic JavaScript Syntax String concatenation operator as well as addition
Image of page 14
Basic JavaScript Syntax Arguments can be any expressions Argument lists are comma-separated
Image of page 15
Basic JavaScript Syntax Object dot notation for method calls as in Java/C++
Image of page 16
Basic JavaScript Syntax
Image of page 17
Basic JavaScript Syntax Many control constructs and use of { } identical to Java/C++
Image of page 18
Basic JavaScript Syntax Most relational operators syntactically same as Java/C++
Image of page 19
Basic JavaScript Syntax Automatic type conversion: guess is String, thinkingOf is Number
Image of page 20
Image of page 21

You've reached the end of your free preview.

Want to read all 51 pages?

  • Summer '19
  • lencha
  • Document Object Model

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes