1 / 18

JavaScript Basics and Fundamentals for Web-Based Systems

Introduction to JavaScript, separation of concerns, importance of styles, structure elements, JavaScript in web development, variables, strings, operators, conditional and looping statements, functions for event handling, and reusability in web-based systems.

digiovanni
Download Presentation

JavaScript Basics and Fundamentals for Web-Based Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. >> Introduction to JavaScript

  2. Separation of Concerns Presentation • Styles the Tags • Provides Tags (Elements) Structure Functional • Modify the Tags Web-based Systems | Misbhauddin

  3. JavaScript - Introduction Run Script (On Load / Action) Request an HTML webpage HTML Page (w/ Scripts) Rules: JS cannot read/write files from/to the computer file system JS cannot execute any other programs JS cannot establish any connection to other computer, except to download a new HTML page or to send mail • JavaScript • Client-Side Scripting Language • It tells the browser to go do the work • Makes Webpages more interactive • JavaScript is not the same as Java • But has various similarities with the programming language • Security Web-Based Systems - Misbhauddin

  4. If No Internet Connection • Open the browser (Chrome) • On a blank page • Right Click on the page and select Inspect • Go to the tab for Console Web-Based Systems - Misbhauddin

  5. Two functions • Popups or Alert Boxes • alert(“message”) • Write function • document.write() • Like the System.out.println() function in Java Web-Based Systems - Misbhauddin

  6. Pop-up Boxes in JS ALERT alert("Welcome to the Class"); CONFIRM confirm("Are you sure you want to take IS-311?"); PROMPT prompt("What is XML?", ":("); Returns a value also Web-Based Systems - Misbhauddin

  7. Variables Variables or Identifiers are named memory locations that hold data to be used throughout the code Syntax value keyword var name = 23; variable name Rules: Case-sensitive Cannot start with a number Can contain letter, numbers & underscore Note: Must be declared before their use in the script var x=23; document.write(x); TRY NOW Web-Based Systems - Misbhauddin

  8. Types of Variables • Numbers: Integers, Decimal Numbers, Negative Numbers • Text / String: “Use quotations for values” • Boolean: true / false • No Value: null (Empty Variable) – Not same as a zero Web-Based Systems - Misbhauddin

  9. Strings in JavaScript • Quotes • You can use both ‘single quotes’ and “double quotes” • For eg: varstr = “This is a sample string”; Escape Characters varx=“I said “Hi” ”; document.write(x); Use backslash (\) to escape • Concatenation • Use the “+” operator to join two strings varx=“Web”; var y= “Systems”; document.write(x + “ “+y); Web-Based Systems - Misbhauddin

  10. Strings in JavaScript • Pre-defined Functions • .length – returns the length of the string • .split(a) – splits the string (later in Arrays) • .substring(a,b) – extracts the substring between a and b • toLowerCase() • toUpperCase() • Conversion • Number to String: Use .toString() function • String to Number: Multiply by 1 • Ensure that the string has only numbers (0-9) Web-Based Systems - Misbhauddin

  11. TRY NOW var a = ‘Hello’; var b = ‘World’; document.write(a+” “+b); document.write(“<br\>”); document.write(a.length); document.write(a.substring(2,4)); Web-Based Systems - Misbhauddin

  12. Operators • “+” • Addition when both are numbers • Concatenation when any is a string • Others • Minus(-), Multiply(*), Divide(/), Remainder(%) • Increment(++), Decrement(--) • Assignment (=) Web-Based Systems - Misbhauddin

  13. Conditional Statement SYNTAX keyword if (something is the case) { more JavaScript commands } • If Statement • execute some code only if a specific condition is met. • Else If Statement • Various conditions that are checked one after another until the script finds a true condition • Else Statement •  If none of the above conditions are met, this block of code is executed. Web-Based Systems - Misbhauddin

  14. Conditional Statement SYNTAX The condition for switch can be a “number” or a “string”. switch(test) { case1: execute code block 1 break; case 2: execute code block 2 break; default: default code } keywords • Switch Statement • Select one of many blocks of code to be executed Web-Based Systems - Misbhauddin

  15. Boolean Conditions Combine Multiple conditions in the IF statement Web-Based Systems - Misbhauddin

  16. Looping Statement SYNTAX keyword • for (initialize; condition; update) • { • more JavaScript commands • } • Initialize outside • while (condition) • { • more JavaScript commands • update inside • } • Initialize outside • do • { • more JavaScript commands • update inside • }while (condition); keyword keyword • Initial Value; Test Condition; Update Value • For Statement • execute some code repeatedly • While Statement • Convenient when you want to loop until a condition changes • Do Statement • Useful when you always want to execute the loop at least once Web-Based Systems - Misbhauddin

  17. Functions in JavaScript SYNTAX keyword • Mainly used for event-handling in Web Development • Can also be called from other functions (Reuse) function name() { } TRY NOW function test() { alert(“Tested”); } Tip: Make it work by calling the function Web-Based Systems - Misbhauddin

  18. Functions in JavaScript function name(parameters) { return b; } • You can use as many parameters as you like • Can also return values (numbers, strings, boolean) • Use return statement function test(x) { alert(x); } TRY NOW Web-Based Systems - Misbhauddin

More Related