Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
C Sharp syntax wikipedia , lookup
Java (programming language) wikipedia , lookup
Smart Pascal wikipedia , lookup
Go (programming language) wikipedia , lookup
Java performance wikipedia , lookup
Control flow wikipedia , lookup
String literal wikipedia , lookup
String (computer science) wikipedia , lookup
C Sharp (programming language) wikipedia , lookup
Web Application Development Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College The Problem Changing the Content of Page Dynamically Efficient Utilization of Resources The Solution How? Scripting Languages Interpreted Languages Purpose “Automate tasks within a particular software environment” JavaScript VBScript JScript Case Sensitive X != x Few Snapshots from History Developed by Brendan Eich (Netscape 2.0) How the Name was Coined? ▪ LiveScript ▪ Renamed to JavaScript (Dec 1995 ) ▪ Marketing Tactics ▪ Similarity with Java (& C++) Standardization Efforts ▪ ECMAScript CSS Flash JavaScript XHTML Java Silverlight Communication Flash Java CSS JavaScript HTML Silverlight Communication Flash Java CSS JavaScript HTML Silverlight Communication Flash Java CSS JavaScript HTML Silverlight Communication Flash Java CSS JavaScript HTML Silverlight Communication How to add JavaScript? <script type=“text/javascript”> & </script> Inclusion Methods ▪ Same File (HTML File) ▪ External File (JS File) ~ Preferred Approach <html> <head> <script type=“text/javascript”> alert("Hello World!"); </script> </head> <body> </body> </html> <html> <head> <script> alert("Hello World!"); </script> <noscript> <h1>Please enable JavaScript!</h1> </noscript> </head> <body> </body> </html> <html> <head> <script> <!-alert("Hello World!"); // --> </script> <noscript> <h1>Please enable JavaScript!</h1> </noscript> </head> <body> </body> </html> alert prompt confirm Number 1 2.3 String “a string” Boolean true false Name it and Have it! Use ‘var’ to declare variables! Examples var num1 = 1; var num2 = 2.3; var str = “A String”; var anyVar; // undefined String Type To append to strings var str1 = “abc”; var str2 = “def”; var strResult = str1 + str2; What about var result = “1” + 2; And var result = “1” - 2; And var someVar ; // No initialization alert(someVar); Boolean Type false ▪ false, undefined, null, 0, NaN, “” (empty string) true ▪ Any other value is considered as true ▪ true, “abc”, 1, … alert(typeof (1)); number alert(typeof(“abc”)); alert(typeof(“1”)); alert(typeof(true)); parseInt Converts a string to an integer number var integerNumber = parseInt(“12”); parseFloat Converts a string to a float number var floatNumber = parseFloat(“12.12”); Converting a Number to a String? Loops For Loop for (start; stop; step) { action } Example for (var i = 0; i < 10; ++i) { alert(i); } While Loop boolean someCondition = true; while (someCondition) { // Do something } Do-While Loop boolean someCondition = true; do { // Do something } while (someCondition); Different forms if (expr) { // Do something } if (expr) { // Do something } else { // Do something } if (expr) { // Do something } else if (expr) { // Do something } else { // Do something } switch (expr) { switch (grade) { case value1: break; case value2: break; case valueN: break; default: break; } case “A”: break; case “B”: break; case “C”: break; default: break; } Objects ▪ “An object in JavaScript is a set of properties, each of which consists of a unique name and a value belonging to one of JavaScript’s six data types” ▪ NO Classes in JavaScript! ▪ Class-Like features. var obj = new Object(); obj.Test = “Some Value”; alert(obj.Test); // Some Value delete obj.Test; alert(obj.Test); // undefined Enumerating Properties for (var aProperty in obj) { alert(aProperty + “ is a property of obj”); } Displays Test is a property of obj Accessing Properties obj[“Test”] = “someValue”; for (var aProperty in obj) { alert(aProperty + “ has value:” + obj[aProperty]); } var str = new String(“This is a string”); var str = new String("abcdef"); var ch = str.charAt(0); var index = str.indexOf("b", 0); if (index > 0) alert("Found at index: " + index); else alert("Not Found!"); split(separater, limit) toLowerCase() toUpperCase() What’s an Array? var ar1 = new Array(); var ar1 = new Array(5); var ar2 = new Array(4, true, “OK”); var ar3 = [4, true, “OK”]; var twoDimAr = [ [ “X”, “O”, “O”], [ “O”, “X”, “O”], [ “O”, “X”, “O”] ]; Access an Element at Index ‘i’ ar[i] = 12; alert(ar[3]); toString splice reverse length push Math abs, ceil, floor, round, random, … Trigonometric, logarithmic, etc Date Dates before January 1, 1970 are not supported What have we learnt today? Need for client side programming Why scripting languages? JavaScript for client side programming Language features of JavaScript