JavaScript Development Introduction First Steps in JavaScript Svetlin Nakov Technical Trainer Software University

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

The Web Warrior Guide to Web Design Technologies
Web Page Behavior IS 373—Web Standards Todd Will.
Dynamic Web Pages Bert Wachsmuth. Review  Internet, IP addresses, ports, client-server, http, smtp  HTML, XHTML, XML  Style Sheets, external, internal,
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Inline, Internal, and External FIle
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
4.1 JavaScript Introduction
JavaScript Basics Course Introduction SoftUni Team Technical Trainers Software University
Software Quality Assurance QA Engineering, Testing, Bug Tracking, Test Automation Software University Technical Trainers SoftUni Team.
W. W. Milner JavaScript. W. W. Milner Chapter 1 - Intro Why use JavaScript? Interactivity LiveScript JavaScript Jscript ECMAScript JavaScript is not Java!
Scripting Languages.
UNIT 3 DYNAMIC WEBSITES WITH CSS AND JAVASCRIPT. OBJECTIVES  CO4 Apply style to a website using CSS.  CO5 Describe the use of scripting when creating.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
AngularJS Services Built-in and Custom Services SoftUni Team Technical Trainers Software University
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
Past, Present and Future Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Unobtrusive JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
JavaScript Development Introduction First Steps in JavaScript SoftUni Team Technical Trainers Software University
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
Svetlin Nakov Technical Trainer Software University
DOM Document Object Model (DOM) SoftUni Team Technical Trainers Software University
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
1 JavaScript
JavaScript Basics Course Introduction Svetlin Nakov Technical Trainer Software University
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
AMD and RequireJS Splitting JavaScript Code into Dependent Modules Software University Technical Trainers SoftUni Team.
SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
Controls, Widgets, Grid…
Jekyll Static Site Generator Template-Based Site Generation Svetlin Nakov Technical Trainer Software University
Web Fundamentals (HTML and CSS) Course Introduction Svetlin Nakov Technical Trainer Software University
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
Web Development Tools Tools for Front-End Developers Writing HTML and CSS Code SoftUni Team Technical Trainers Software University
Web Fundamentals (HTML and CSS)
JQuery Overview Unleash the Power of jQuery SoftUni Team Technical Trainers Software University
Responsive Design Design that Adapts to Different Devices SoftUni Team Technical Trainers Software University
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Bootstrap Front-End Framework for Responsive Web Sites Svetlin Nakov Technical Trainer Software University
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
JavaScript Tools Tools for Writing / Editing / Debugging JavaScript Code Svetlin Nakov Technical Trainer Software University
The Magic of Dynamic Web Pages Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
The Magic of Dynamic Web Pages Telerik Software Academy JavaScript Fundamentals.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University
Introduction to.
Extending functionality using Collections
Web Development & Design Foundations with HTML5 7th Edition
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to JavaScript Development
14 A Brief Look at JavaScript and jQuery.
Presentation transcript:

JavaScript Development Introduction First Steps in JavaScript Svetlin Nakov Technical Trainer Software University

Table of Contents 1.Static vs. Dynamic Languages 2.Dynamic HTML (DHTML) 3.Introduction to JavaScript  JavaScript in Web Pages  Integrating JavaScript in HTML 4.First Steps in JavaScript 5.JavaScript Syntax 6.Browser and JavaScript Objects 7.Debugging in JavaScript 2

3 Static Languages  Explicit type declaration  Strongly typed  Type checking occurs on compile time  Statically-typed languages: C, C++, C#, Java Static vs. Dynamic Languages Dynamic (Scripting) Languages  Implicit type declaration  Weakly typed  Type checking occurs at run time  Dynamic languages: JavaScript, PHP, Python, Ruby string name = "Pesho" int age = 25; var name = "Pesho" var age = 25;

4  A compiler converts a high level language code (like C#, Java) into machine code which is executed by the CPU or VM  Most errors are found at compile time, before execution  C and C++ use compilers to produce native code for the CPU  C# and Java use compilers to produce intermediate code for VM  An interpreter analyses and executes the script code line by line  Code is analyzed at runtime (no compilation)  Errors are found at runtime, during the code execution  JavaScript, Python, Ruby and PHP use interpreters Compiler / Interpreter / Virtual Machine

5  JIT (just-in time compilers) compile the code at runtime, during the execution, on demand  Available for Java, JavaScript and other languages  Compiled languages are faster than interpreted languages  C, C++, Go and Swift are very fast  compiled to native code for CPU  C# and Java are slower  compiled to intermediate code for VM  JS, Python, Ruby, PHP are even slower  interpreted / JIT-compiled  Virtual machine (JVM for Java, CLR for C# /.NET)  A virtual computer inside the computer, runs intermediate code Compiler / Interpreter / Virtual Machine (2)

Dynamic HTML Dynamic Behavior at the Client Side

7  DHTML: collection of technologies used together to create interactive web sites  Web pages to react and change in response to the user’s actions  DHTML is combination of HTML + CSS + JavaScript + DOM What is DHTML?DHTML HTMLCSSJavaScriptDOM

8  HTML defines web sites content through semantic tags (headings, sections, articles, paragraphs, lists, …)  CSS describes the look and formatting of a document  Layout and Position of elements on the page  Presentation styles (background, borders, colors…)  Text and font styles (size, color, family)  JavaScript defines dynamic behavior  Programming logic for interaction with the user  Handle user events DHTML = HTML + CSS + JavaScript

JavaScript Dynamic Behavior in a Web Page

10  JavaScript is a scripting programming language  Developed by Netscape for dynamic Web content  Lightweight, but with limited capabilities  Can be used as object-oriented language  Embedded in HTML page, interpreted by the Web browser  Client-side, server-side, mobile and desktop technology  Dynamic (scripting) language  weakly typed, runtime object alternation, functional programming, runtime code eval, etc.  Powerful to manipulate the DOM What is JavaScript?

11  JavaScript allows interactivity such as:  Dynamically load and change page content (through AJAX)  Implementing custom HTML UI controls  Sortable table, 3D charts, asynchronous file upload, …  Implementing advanced form validation  Respond to user actions, e.g. handle keyboard events  Performing complex calculations, e.g. SHA1 encryption  Implementing browser-based interactive games  Implementing Single Page Applications (SPA) JavaScript Advantages

12  Can handle events, e.g. button clicks  Can read and write HTML elements and modify the DOM tree  Can access / modify browser cookies  Can detect the user’s browser and OS  Can be used as object-oriented language  Can perform asynchronous server calls (AJAX)  Can implement complex graphics / animation (through Canvas)  Can implement back-end logic (through Node.js) What Can JavaScript Do?

13  JS engine – a virtual machine which interprets / executes JavaScript  Used in web Browsers  V8 in Chrome  Chakra in IE  Spidermonkey in Firefox  JavaScriptCore for Safari  Services  Memory management / GC  Just-in-Time compilation  Type System JavaScript Engines

14 First Look at JavaScript Code <html><body> var name = "Nakov"; var name = "Nakov"; alert("Hello, " + name + "!\nRegards from JavaScript!"); alert("Hello, " + name + "!\nRegards from JavaScript!"); </body></html>

First Look at JavaScript Live Demo

16  The JavaScript code can be placed in:  tag in the head  tag in the body  External files (recommended), linked via  Files usually have.js extension  The.js files are cached by the browser Using JavaScript Code </script>

17  Using external JS files:  External JavaScript file ( sample.js ): Using External Script Files <html><head> </head><body> </body></html> function alertMessage() { alert('Hello from sample.js!') alert('Hello from sample.js!')} external-JavaScript.html sample.js The tag is always empty. Cannot be.

18  Attributes ( async and defer ) load a script in background  Without pausing the HTML parser  async  Executed asynchronously as soon as the script is downloaded  Without blocking the browser in the meantime  defer  Executed in after the entire document has been loaded Modern Approach to Load JS Files

19  JavaScript code is executed during the page loading or when the browser fires an event  All statements are executed at page loading  Some statements just define functions that can be called later  No compile-time checks (JavaScript is dynamic language)  Function calls or code can be attached as "event handlers"  Executed when the event is fired by the browser JavaScript – When is Executed?

Executing JavaScript Code Live Demo

The JavaScript Syntax

22  The JavaScript syntax is similar to C#  Operators ( +, *, =, !=, &&, ++, …)  Variables (typeless)  Conditional statements ( if, else )  Loops ( for, while )  Arrays ( my_arr[5] ) and associative arrays ( my_arr['abc'] )  Functions (can return value)  Function variables (variables holding a function reference) JavaScript Syntax

23  Alert box with text and [OK] button  Just a message shown in a dialog box:  Confirmation box  Contains text, [OK] button and [Cancel] button:  Prompt box  Contains text, input field with default value: Standard Popup Boxes confirm("Are you sure?"); prompt("enter amount", 10); alert("Some text here");

Syntax and Popup Boxes Live Demo

Event Handlers

<html><head> function clickHandler(message) { function clickHandler(message) { alert(message); alert(message); }</script></head><body> <img src="logo.gif" <img src="logo.gif" onclick="clickHandler('clicked!')" /> onclick="clickHandler('clicked!')" /></body></html> 26 Calling a JavaScript Function from Event

Event Handlers in JavaScript Live Demo

The Built-In Browser Objects

29  The browser provides some read-only data via:  window  The top node of the DOM tree  Represents the browser's window  document  Holds information of the current loaded document  screen  Holds the user’s display properties  navigator  Holds information about the browser Built-in Browser Objects

30 DOM Hierarchy – Example window navigatorscreendocumenthistorylocation form inputbutton div div p imgul

31  window.open() Opening New Window – Example var newWindow = window.open("", "sampleWindow", "width=300, height=100, menubar=yes, status=yes, resizable=yes"); newWindow.document.write( " " Sample Title Sample Title Sample Sample Text "); Text "); newWindow.status = "Hello folks"; "Hello folks"; window-open.html

32 The Navigator Object alert(window.navigator.userAgent); The browser window The navigator in the browser window The userAgent (browser ID)

33  document object  Provides some built-in arrays of specific objects on the currently loaded Web page  document.location  Used to access the currently open URL or redirect the browser The Screen Object document.links[0].href = "yahoo.com"; document.write("This is some bold text "); document.location = "

Built-In Browser Objects Live Demo

Other JavaScript Objects

36  The Math object provides some mathematical functions The Math Object for (var i=1; i<=20; i++) { var x = Math.random(); var x = Math.random(); x = 10*x + 1; x = 10*x + 1; x = Math.floor(x); x = Math.floor(x); document.write( document.write( "Random number (" + "Random number (" + i + ") in range " + i + ") in range " + " > " + x + " > " + x + " "); " ");} math.html

37  The Date object provides date / calendar functions The Date Object var now = new Date(); var result = "The time is " + now; document.getElementById("timeField").innerText = result; … dates.html

38  Make something happen (once) after a fixed delay Timers: setTimeout() var timer = setTimeout('bang()', 5000); clearTimeout(timer); 5 seconds after his statement executes, this function is called Cancels the timer

39  Make something happen repeatedly at fixed intervals Timers: setInterval() var timer = setInterval('clock()', 1000); clearInterval(timer); This function is called continuously per 1 second. Stops the timer.

40 Timer – Example function timerFunc() { function timerFunc() { var now = new Date(); var now = new Date(); var hour = now.getHours(); var hour = now.getHours(); var min = now.getMinutes(); var min = now.getMinutes(); var sec = now.getSeconds(); var sec = now.getSeconds(); document.getElementById("clock").value = document.getElementById("clock").value = "" + hour + ":" + min + ":" + sec; "" + hour + ":" + min + ":" + sec; } setInterval('timerFunc()', 1000); setInterval('timerFunc()', 1000);</script> timer-demo.html

Other JavaScript Objects Live Demo

Debugging JavaScript

43  Modern browsers have JavaScript console where errors in scripts are reported  Errors may differ across browsers  Several tools to debug JavaScript  Microsoft Script Editor  Add-on for Internet Explorer  Supports breakpoints, watches  JavaScript statement debugger ; opens the script editor Debugging JavaScript

44  Firebug  Firefox add-on for debugging JavaScript, CSS, HTML  Supports breakpoints, watches, JavaScript console editor  Very useful for CSS and HTML too  You can edit all the document real-time: CSS, HTML, etc  Shows how CSS rules apply to element  Shows Ajax requests and responses  Firebug is written mostly in JavaScript Firebug

45 Firebug (2)

46  The console object exists only if there is a debugging tool that supports it  Used to write log messages at runtime  Methods of the console object:  debug(message)  info(message)  log(message)  warn(message)  error(message) JavaScript Console Object

47 1.DHTML = HTML + CSS + JavaScript + DOM 2.JavaScript – dynamical scripting language  Executed in the Web browsers / server-side  Enables dynamic behavior 3.The DOM hierarchy  window, document, body, form, … 4.Debugging JS code  JS Console, Firebug, [F12] Summary

? ? ? ? ? ? ? ? ? JavaScript Development Introduction

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 49  Attribution: this work may contain portions from  “JavaScript Basics" course by Telerik Academy under CC-BY-NC-SA licenseJavaScript BasicsCC-BY-NC-SA

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg