ES6 – Multimedia ”; Previous Next The JavaScript navigator object includes a child object called plugins. This object is an array, with one entry for each plug-in installed on the browser. The navigator.plugins object is supported only by Netscape, Firefox, and Mozilla. Example The following example shows how to list down all the plug-ins installed in your browser. <html> <head> <title>List of Plug-Ins</title> </head> <body> <table border = “1”> <tr> <th>Plug-in Name</th> <th>Filename</th> <th>Description</th> </tr> <script LANGUAGE = “JavaScript” type = “text/javascript”> for (i = 0; i<navigator.plugins.length; i++) { document.write(“<tr><td>”); document.write(navigator.plugins[i].name); document.write(“</td><td>”); document.write(navigator.plugins[i].filename); document.write(“</td><td>”); document.write(navigator.plugins[i].description); document.write(“</td></tr>”); } </script> </table> </body> </html> Output The following output is displayed on successful execution of the above code. Checking for Plugins Each plug-in has an entry in the array. Each entry has the following properties − name − The name of the plug-in. filename − The executable file that was loaded to install the plug-in. description − A description of the plug-in, supplied by the developer. mimeTypes − An array with one entry for each MIME type supported by the plugin. You can use these properties in a script to find out the installed plug-ins, and then using JavaScript, you can play the appropriate multimedia file. Take a look at the following code. <html> <head> <title>Using Plug-Ins</title> </head> <body> <script language = “JavaScript” type = “text/javascript”> media = navigator.mimeTypes[“video/quicktime”]; if (media) { document.write(“<embed src = ”quick.mov” height = 100 width = 100>”); } else { document.write(“<img src = ”quick.gif” height = 100 width = 100>”); } </script> </body> </html> Note − Here we are using HTML <embed> tag to embed a multimedia file. Controlling Multimedia Let us take a real example which works in almost all the browsers. <html> <head> <title>Using Embeded Object</title> <script type = “text/javascript”> <!– function play() { if (!document.demo.IsPlaying()) { document.demo.Play(); } } function stop() { if (document.demo.IsPlaying()){ document.demo.StopPlay(); } } function rewind() { if (document.demo.IsPlaying()){ document.demo.StopPlay(); } document.demo.Rewind(); } // –> </script> </head> <body> <embed id = “demo” name = “demo” src = “http://www.amrood.com/games/kumite.swf” width = “318” height = “300” play = “false” loop = “false” pluginspage = “http://www.macromedia.com/go/getflashplayer” swliveconnect = “true”> </embed> <form name = “form” id = “form” action = “#” method = “get”> <input type = “button” value = “Start” onclick = “play();” /> <input type = “button” value = “Stop” onclick = “stop();” /> <input type = “button” value = “Rewind” onclick = “rewind();” /> </form> </body> </html> Print Page Previous Next Advertisements ”;
Category: es6
ES6 – Validations
ES6 – Validations ”; Previous Next Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button. If the data entered by the client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with the correct information. This was really a lengthy process which used to put a lot of burden on the server. JavaScript provides a way to validate the form”s data on the client”s computer before sending it to the web server. Form validation generally performs two functions. Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data. Data Format Validation − Secondly, the data that is entered must be checked for correct form and value. Your code must include appropriate logic to test the correctness of data. Example We will take an example to understand the process of validation. Here is a simple form in html format. <html> <head> <title>Form Validation</title> <script type = “text/javascript”> <!– // Form validation code will come here. // –> </script> </head> <body> <form action = “/cgi-bin/test.cgi” name = “myForm” onsubmit = “return(validate());”> <table cellspacing = “2” cellpadding = “2” border = “1”> <tr> <td align = “right”>Name</td> <td><input type = “text” name = “Name” /></td> </tr> <tr> <td align = “right”>EMail</td> <td><input type = “text” name = “EMail” /></td> </tr> <tr> <td align = “right”>Zip Code</td> <td><input type = “text” name = “Zip” /></td> </tr> <tr> <td align = “right”>Country</td> <td> <select name = “Country”> <option value = “-1” selected>[choose yours]</option> <option value = “1”>USA</option> <option value = “2”>UK</option> <option value = “3”>INDIA</option> </select> </td> </tr> <tr> <td align = “right”></td> <td><input type = “submit” value = “Submit” /></td> </tr> </table> </form> </body> </html> Output The following output is displayed on successful execution of the above code. Basic Form Validation First let us see how to do a basic form validation. In the above form, we are calling validate() to validate data when onsubmit event is occurring. The following code shows the implementation of this validate() function. <script type = “text/javascript”> <!– // Form validation code will come here. function validate() { if( document.myForm.Name.value == “” ) { alert( “Please provide your name!” ); document.myForm.Name.focus() ; return false; } if( document.myForm.EMail.value == “” ) { alert( “Please provide your Email!” ); document.myForm.EMail.focus() ; return false; } if( document.myForm.Zip.value == “” || isNaN( document.myForm.Zip.value ) || document.myForm.Zip.value.length != 5 ) { alert( “Please provide a zip in the format #####.” ); document.myForm.Zip.focus() ; return false; } if( document.myForm.Country.value == “-1” ) { alert( “Please provide your country!” ); return false; } return( true ); } // –> </script> Data Format Validation Now we will see how we can validate our entered form data before submitting it to the web server. The following example shows how to validate an entered email address. An email address must contain at least a ‘@’ sign and a dot (.). Also, the ‘@’ must not be the first character of the email address, and the last dot must at least be one character after the ‘@’ sign Example Try the following code for email validation. <script type = “text/javascript”> <!– function validateEmail() { var emailID = document.myForm.EMail.value; atpos = emailID.indexOf(“@”); dotpos = emailID.lastIndexOf(“.”); if (atpos < 1 || ( dotpos – atpos < 2 )) { alert(“Please enter correct email ID”) document.myForm.EMail.focus() ; return false; } return( true ); } // –< </script> Print Page Previous Next Advertisements ”;
ES6 – Promises
ES6 – Promises ”; Previous Next Promise Syntax The Syntax related to promise is mentioned below where, p is the promise object, resolve is the function that should be called when the promise executes successfully and reject is the function that should be called when the promise encounters an error. let p = new Promise(function(resolve,reject){ let workDone = true; // some time consuming work if(workDone){ //invoke resolve function passed resolve(”success promise completed”) } else{ reject(”ERROR , work could not be completed”) } }) Example The example given below shows a function add_positivenos_async() which adds two numbers asynchronously. The promise is resolved if positive values are passed. The promise is rejected if negative values are passed. <script> function add_positivenos_async(n1, n2) { let p = new Promise(function (resolve, reject) { if (n1 >= 0 && n2 >= 0) { //do some complex time consuming work resolve(n1 + n2) } else reject(”NOT_Postive_Number_Passed”) }) return p; } add_positivenos_async(10, 20) .then(successHandler) // if promise resolved .catch(errorHandler);// if promise rejected add_positivenos_async(-10, -20) .then(successHandler) // if promise resolved .catch(errorHandler);// if promise rejected function errorHandler(err) { console.log(”Handling error”, err) } function successHandler(result) { console.log(”Handling success”, result) } console.log(”end”) </script> The output of the above code will be as mentioned below − end Handling success 30 Handling error NOT_Postive_Number_Passed Promises Chaining Promises chaining can be used when we have a sequence of asynchronous tasks to be done one after another. Promises are chained when a promise depends on the result of another promise. This is shown in the example below Example In the below example, add_positivenos_async() function adds two numbers asynchronously and rejects if negative values are passed. The result from the current asynchronous function call is passed as parameter to the subsequent function calls. Note each then() method has a return statement. <script> function add_positivenos_async(n1, n2) { let p = new Promise(function (resolve, reject) { if (n1 >= 0 && n2 >= 0) { //do some complex time consuming work resolve(n1 + n2) } else reject(”NOT_Postive_Number_Passed”) }) return p; } add_positivenos_async(10,20) .then(function(result){ console.log(“first result”,result) return add_positivenos_async(result,result) }).then(function(result){ console.log(“second result”,result) return add_positivenos_async(result,result) }).then(function(result){ console.log(“third result”,result) }) console.log(”end”) </script> The output of the above code will be as stated below − end first result 30 second result 60 third result 120 Some common used methods of the promise object are discussed below in detail − promise.all() This method can be useful for aggregating the results of multiple promises. Syntax The syntax for the promise.all() method is mentioned below, where, iterable is an iterable object. E.g. Array. Promise.all(iterable); Example The example given below executes an array of asynchronous operations [add_positivenos_async(10,20),add_positivenos_async(30,40),add_positivenos_async(50,60)]. When all the operations are completed, the promise is fully resolved. <script> function add_positivenos_async(n1, n2) { let p = new Promise(function (resolve, reject) { if (n1 >= 0 && n2 >= 0) { //do some complex time consuming work resolve(n1 + n2) } else reject(”NOT_Postive_Number_Passed”) }) return p; } //Promise.all(iterable) Promise.all([add_positivenos_async(10,20),add_positivenos_async(30,40),add_positivenos_async(50,60)]) .then(function(resolveValue){ console.log(resolveValue[0]) console.log(resolveValue[1]) console.log(resolveValue[2]) console.log(”all add operations done”) }) .catch(function(err){ console.log(”Error”,err) }) console.log(”end”) </script> The output of the above code will be as follows − end 30 70 110 all add operations done promise.race() This function takes an array of promises and returns the first promise that is settled. Syntax The syntax for the promise.race() function is mentioned below, where, iterable is an iterable object. E.g. Array. Promise.race(iterable) Example The example given below takes an array [add_positivenos_async(10,20),add_positivenos_async(30,40)] of asynchronous operations. The promise is resolved whenever any one of the add operation completes. The promise will not wait for other asynchronous operations to complete. <script> function add_positivenos_async(n1, n2) { let p = new Promise(function (resolve, reject) { if (n1 >= 0 && n2 >= 0) { //do some complex time consuming work resolve(n1 + n2) } else reject(”NOT_Postive_Number_Passed”) }) return p; } //Promise.race(iterable) Promise.race([add_positivenos_async(10,20),add_positivenos_async(30,40)]) .then(function(resolveValue){ console.log(”one of them is done”) console.log(resolveValue) }).catch(function(err){ console.log(“Error”,err) }) console.log(”end”) </script> The output of the above code will be as follows − end one of them is done 30 Promises are a clean way to implement async programming in JavaScript (ES6 new feature). Prior to promises, Callbacks were used to implement async programming. Let’s begin by understanding what async programming is and its implementation, using Callbacks. Understanding Callback A function may be passed as a parameter to another function. This mechanism is termed as a Callback. A Callback would be helpful in events. The following example will help us better understand this concept. <script> function notifyAll(fnSms, fnEmail) { console.log(”starting notification process”); fnSms(); fnEmail(); } notifyAll(function() { console.log(“Sms send ..”); }, function() { console.log(“email send ..”); }); console.log(“End of script”); //executes last or blocked by other methods </script> In the notifyAll() method shown above, the notification happens by sending SMS and by sending an e-mail. Hence, the invoker of the notifyAll method has to pass two functions as parameters. Each function takes up a single responsibility like sending SMS and sending an e-mail. The following output is displayed on successful execution of the above code. starting notification process Sms send .. Email send .. End of script In the code mentioned above, the function calls are synchronous. It means the UI thread would be waiting to complete the entire notification process. Synchronous calls become blocking calls. Let”s understand non-blocking or async calls now. Understanding AsyncCallback Consider the above example. To enable the script, execute an asynchronous or a non-blocking call to notifyAll() method. We shall use the setTimeout() method
ES6 – Classes
ES6 – Classes ”; Previous Next Object Orientation is a software development paradigm that follows real-world modelling. Object Orientation, considers a program as a collection of objects that communicates with each other via mechanism called methods. ES6 supports these object-oriented components too. Object-Oriented Programming Concepts To begin with, let us understand Object − An object is a real-time representation of any entity. According to Grady Brooch, every object is said to have 3 features − State − Described by the attributes of an object. Behavior − Describes how the object will act. Identity − A unique value that distinguishes an object from a set of similar such objects. Class − A class in terms of OOP is a blueprint for creating objects. A class encapsulates data for the object. Method − Methods facilitate communication between objects. Let us translate these Object-Oriented concepts to the ones in the real world. For example: A car is an object that has data (make, model, number of doors, Vehicle Number, etc.) and functionality (accelerate, shift, open doors, turn on headlights, etc.) Prior to ES6, creating a class was a fussy affair. Classes can be created using the class keyword in ES6. Classes can be included in the code either by declaring them or by using class expressions. Syntax: Declaring a Class class Class_name { } Syntax: Class Expressions var var_name = new Class_name { } The class keyword is followed by the class name. The rules for identifiers (already discussed) must be considered while naming a class. A class definition can include the following − Constructors − Responsible for allocating memory for the objects of the class. Functions − Functions represent actions an object can take. They are also at times referred to as methods. These components put together are termed as the data members of the class. Note − A class body can only contain methods, but not data properties. Example: Declaring a class class Polygon { constructor(height, width) { this.height = height; this.width = width; } } Example: Class Expression var Polygon = class { constructor(height, width) { this.height = height; this.width = width; } } The above code snippet represents an unnamed class expression. A named class expression can be written as. var Polygon = class Polygon { constructor(height, width) { this.height = height; this.width = width; } } Note − Unlike variables and functions, classes cannot be hoisted. Creating Objects To create an instance of the class, use the new keyword followed by the class name. Following is the syntax for the same. var object_name= new class_name([ arguments ]) Where, The new keyword is responsible for instantiation. The right hand side of the expression invokes the constructor. The constructor should be passed values if it is parameterized. Example: Instantiating a class var obj = new Polygon(10,12) Accessing Functions A class’s attributes and functions can be accessed through the object. Use the ‘.’ dot notation (called as the period) to access the data members of a class. //accessing a function obj.function_name() Example: Putting them together ”use strict” class Polygon { constructor(height, width) { this.h = height; this.w = width; } test() { console.log(“The height of the polygon: “, this.h) console.log(“The width of the polygon: “,this. w) } } //creating an instance var polyObj = new Polygon(10,20); polyObj.test(); The Example given above declares a class ‘Polygon’. The class’s constructor takes two arguments – height and width respectively. The ‘this’ keyword refers to the current instance of the class. In other words, the constructor above initializes two variables h and w with the parameter values passed to the constructor. The test () function in the class, prints the values of the height and width. To make the script functional, an object of the class Polygon is created. The object is referred to by the polyObj variable. The function is then called via this object. The following output is displayed on successful execution of the above code. The height of the polygon: 10 The width of the polygon: 20 Setters and Getters Setters A setter function is invoked when there is an attempt to set the value of a property. The set keyword is used to define a setter function. The syntax for defining a setter function is given below − {set prop(val) { . . . }} {set [expression](val) { . . . }} prop is the name of the property to bind to the given function. val is an alias for the variable that holds the value attempted to be assigned to property. expression with ES6, can be used as a property name to bind to the given function. Example <script> class Student { constructor(rno,fname,lname){ this.rno = rno this.fname = fname this.lname = lname console.log(”inside constructor”) } set rollno(newRollno){ console.log(“inside setter”) this.rno = newRollno } } let s1 = new Student(101,”Sachin”,”Tendulkar”) console.log(s1) //setter is called s1.rollno = 201 console.log(s1) </script> The above example defines a class Student with three properties namely rno, fname and lname. A setter function rollno() is used to set the value for the rno property. The output of the above code will be as shown below − inside constructor Student {rno: 101, fname: “Sachin”, lname: “Tendulkar”} inside setter Student {rno: 201, fname: “Sachin”, lname: “Tendulkar”} Example The following example shows how to use an expression as
ES6 – Symbol
ES6 – Symbol ”; Previous Next Introduction to Symbol ES6 introduces a new primitive type called Symbol. They are helpful to implement metaprogramming in JavaScript programs. Syntax const mySymbol = Symbol() const mySymbol = Symbol(stringDescription) A symbol is just a piece of memory in which you can store some data. Each symbol will point to a different memory location. Values returned by a Symbol() constructor are unique and immutable. Example Let us understand this through an example. Initially, we created two symbols without description followed by symbols with same description. In both the cases the equality operator will return false when the symbols are compared. <script> const s1 = Symbol(); const s2 = Symbol(); console.log(typeof s1) console.log(s1===s2) const s3 = Symbol(“hello”);//description const s4 = Symbol(“hello”); console.log(s3) console.log(s4) console.log(s3==s4) </script> The output of the above code will be as mentioned below − symbol false Symbol(hello) Symbol(hello) false Sr.No Property & Description 1 Symbol.for(key) searches for existing symbols in a symbol registry with the given key and returns it, if found. Otherwise, a new symbol gets created in the global symbol registry with this key. 2 Symbol.keyFor(sym) Retrieves a shared symbol key from the global symbol registry for the given symbol. Symbol & Classes A symbol can be used with classes to define the properties in the class. The advantage is that if property is a symbol as shown below, the property can be accessed outside the package only if the symbol name is known. So, data is much encapsulated when symbols are used as properties. Example <script> const COLOR = Symbol() const MODEL = Symbol() const MAKE = Symbol() class Bike { constructor(color ,make,model){ this[COLOR] = color; this[MAKE] = make; this[MODEL] = model; } } let bike = new Bike(”red”,”honda”,”cbr”) console.log(bike) //property can be accessed ony if symbol name is known console.log(bike[COLOR]) </script> The output of the above code will be as stated below − Bike {Symbol(): “red”, Symbol(): “honda”, Symbol(): “cbr”} red Print Page Previous Next Advertisements ”;
ES6 – Discussion
Discuss ES6 ”; Previous Next European Computer Manufacturers Association (ECMAScript) or (ES) is a standard for scripting languages like JavaScript, ActionScript and JScript. It was initially created to standardize JavaScript, which is the most popular implementation of ECMAScript. This tutorial adopts a simple and practical approach through JavaScript to describe the new features in ECMAScript 2015 (ES6), ECMAScript 2016 (ES7), ECMAScript 2017(ES8) and ECMAScript 2018 (ES9). Print Page Previous Next Advertisements ”;
ES6 – Page Redirect
ES6 – Page Redirect ”; Previous Next Redirect is a way to send both users and search engines to a different URL from the one they originally requested. Page redirection is a way to automatically redirect a web page to another web page. The redirected page is often on the same website, or it can be on a different website or a web server. JavaScript Page Redirection window.location and window.location.href In JavaScript, you can use many methods to redirect a web page to another one. Almost all methods are related to window.location object, which is a property of the Window object. It can be used to get the current URL address (web address) and to redirect the browser to a new page. Both usages are same in terms of behavior. window.location returns an object. If .href is not set, window.location defaults to change the parameter .href. Example <!DOCTYPE html> <html> <head> <script> function newLocation() { window.location = “http://www.xyz.com”; } </script> </head> <body> <input type = “button” value = “Go to new location” onclick = “newLocation()”> </body> </html> location.replace() The other most frequently used method is the replace() method of window.location object, it will replace the current document with a new one. In replace() method, you can pass a new URL to replace() method and it will perform an HTTP redirect. Following is the syntax for the same. window.location.replace(“http://www.abc.com location.assign() The location.assign() method loads a new document in the browser window. Following is the syntax for the same. window.location.assign(“http://www.abc.org”); assign() vs. replace() The difference between assign() and replace() method is that the location.replace() method deletes the current URL from the document history, so it is unable to navigate back to the original document. You can”t use the browsers “Back” button in this case. If you want to avoid this situation, you should use location.assign() method, because it loads a new Document in the browser. location.reload() The location.reload() method reloads the current document in the browser window. Following is the syntax for the same. window.location.reload(“http://www.yahoo.com”); window.navigate() The window.navigate() method is similar to assigning a new value to the window.location.href property. Because it is only available in MS Internet Explorer, so you should avoid using this in cross-browser development. Following is the syntax for the same. window.navigate(“http://www.abc.com”); Redirection and Search Engine Optimization If you want to notify the search engines (SEO) about your URL forwarding, you should add the rel = “canonical” meta tag to your website head part because search engines don”t analyze JavaScript to check the redirection. Following is the syntax for the same. <link rel = “canonical” href = “http://abc.com/” /> Print Page Previous Next Advertisements ”;
ES6 – Useful Resources
ES6 – Useful Resources ”; Previous Next The following resources contain additional information on ES6. Please use them to get more in-depth knowledge on this topic. Useful Video Courses JavaScript Masterclass: ES6 Modern Development 71 Lectures 4.5 hours Frahaan Hussain More Detail Webpack Course for Beginners 46 Lectures 9.5 hours Eduonix Learning Solutions More Detail JavaScript fundamentals Course for Beginners: JavaScript ES6 37 Lectures 2 hours Laurence Svekis More Detail Pure JavaScript Calculator – JavaScript ES6 12 Lectures 41 mins Laurence Svekis More Detail JavaScript Data Pagination Code JavaScript ES6 Project Code 13 Lectures 49 mins Laurence Svekis More Detail JavaScript Core fundamentals Learn JavaScript Here Code ES6 46 Lectures 3 hours Laurence Svekis More Detail Print Page Previous Next Advertisements ”;
ES6 – Quick Guide
ES6 – Quick Guide ”; Previous Next ES6 – Overview ECMAScript (ES) is a scripting language specification standardized by ECMAScript International. It is used by applications to enable client-side scripting. The specification is influenced by programming languages like Self, Perl, Python, Java etc. Languages like JavaScript, Jscript and ActionScript are governed by this specification. This tutorial introduces you to ES6 implementation in JavaScript. JavaScript JavaScript was developed by Brendan Eich, a developer at Netscape Communications Corporation, in 1995.JavaScript started life with the name Mocha, and was briefly named LiveScript before being officially renamed to JavaScript. It is a scripting language that is executed by the browser, i.e. on the client’s end. It is used in conjunction with HTML to develop responsive webpages. ECMA Script6’s implementation discussed here covers the following new features − Support for constants Block Scope Arrow Functions Extended Parameter Handling Template Literals Extended Literals Enhanced Object Properties De-structuring Assignment Modules Classes Iterators Generators Collections New built in methods for various classes Promises ECMAScript Versions There are nine editions of ECMA-262 which are as follows − Edition Name Description 1 ECMAScript 1 First Edition released in 1997 2 ECMAScript 2 Second Edition released in 1998, minor changes to meet ISO/IEC 16262 standard 3 ECMAScript 3 Third Edition released in 1999 with language enhancements 4 ECMAScript 4 Fourth Edition release plan was dropped, few features added later in ES6 & other complex features dropped 5 ECMAScript 5 Fifth Edition released in 2009 5.1 ECMAScript 5.1 5.1 Edition released in 2011, minor changes to meet ISO/IEC 16262:2011 standard 6 ECMAScript 2015/ES6 Sixth Edition released in 2015, see ES6 chapters for new features 7 ECMAScript 2016/ES7 Seventh Edition released in 2016, see ES7 chapters for new features 8 ECMAScript 2017/ES8 Eight Edition released in 2017, see ES8 chapters for new features 9 ECMAScript 2018/ES9 Ninth Edition released in 2018, see ES9 chapters for new features ES6 – Environment In this chapter, we will discuss the setting up of the environment for ES6. Local Environment Setup JavaScript can run on any browser, any host, and any OS. You will need the following to write and test a JavaScript program standard − Text Editor The text editor helps you to write your source code. Examples of few editors include Windows Notepad, Notepad++, Emacs, vim or vi etc. Editors used may vary with the operating systems. The source files are typically named with the extension.js Installing Node.js Node.js is an open source, cross-platform runtime environment for server-side JavaScript. Node.js is required to run JavaScript without a browser support. It uses Google V8 JavaScript engine to execute the code. You may download Node.js source code or a pre-built installer for your platform. Node is available at https://nodejs.org/en/download Installation on Windows Download and run the .msi installer for Node To verify if the installation was successful, enter the command node –v in the terminal window. Installation on Mac OS X To install node.js on OS X you can download a pre-compiled binary package which makes a nice and easy installation. Head over to www.nodejs.org and click the install button to download the latest package. Install the package from the .dmg by following along the install wizard which will install both node and npm. npm is the Node Package Manager which facilitates installs of additional packages for Node.js. Installation on Linux You need to install a number of dependencies before you can install Node.js and npm. Ruby and GCC. You’ll need Ruby 1.8.6 or newer and GCC 4.2 or newer Homebrew. Homebrew is a package manager originally for the Mac, but it’s been ported to Linux as Linuxbrew. You can learn more about Homebrew at the http://brew.sh/ at the http://brew.sh/linuxbrew. Integrated Development Environment (IDE) Support JavaScript can be built on a plethora of development environments like Visual Studio, Sublime Text 2, WebStorm/PHPStorm, Eclipse, Brackets, etc. The Visual Studio Code and Brackets IDE is discussed in this section. The development environment used here is Visual Studio Code (Windows platform). Visual Studio Code This is open source IDE from Visual Studio. It is available for Mac OS X, Linux, and Windows platforms. VScode is available at https://code.visualstudio.com. Installation on Windows Download Visual Studio Code for Windows. Double-click on VSCodeSetup.exe to launch the setup process. This will only take a minute. Following is the screenshot of the IDE. You may directly traverse to the file’s path by a right-click on the file → open in command prompt. Similarly, the Reveal in Explorer option shows the file in the File Explorer. Installation on Mac OS X Visual Studio Code’s Mac OS X specific installation guide can be found at https://code.visualstudio.com/docs/setup/setup-overview Installation on Linux Linux specific installation guide for Visual Studio Code can be found at https://code.visualstudio.com/Docs/editor/setup. Brackets Brackets is a free open-source editor for web development, created by Adobe Systems. It is available for Linux, Windows and Mac OS X. Brackets is available at http://brackets.io. You can run DOS prompt/Shell within Brackets itself by adding one more extension Brackets Shell. Upon installation, you will find an icon of shell on the right hand side of the editor . Once you click on the icon, you will see the shell window as shown in the following screenshot. You are all set!!! ES6 – Syntax Syntax defines the set of rules for writing programs. Every language specification defines its own syntax. A JavaScript program can be composed of − Variables − Represents a named memory block that can store values for the program. Literals − Represents constant/fixed values. Operators − Symbols that define how the operands will be processed. Keywords − Words that have a special meaning in the context of a language. The following table lists some keywords in JavaScript. Some commonly used keywords are listed in the following table. break as any Switch case if throw Else var number string Get module type instanceof Typeof finally for enum Export while void this New null super Catch let static return True False Modules − Represents code blocks that
ES6 – Image Map
ES6 – Image Map ”; Previous Next You can use JavaScript to create a client-side image map. Client-side image maps are enabled by the usemap attribute for the <img /> tag and defined by special <map> and <area> extension tags. The image that is going to form the map is inserted into the page using the <img /> element as normal, except that it carries an extra attribute called usemap. The value of the usemap attribute is the value of the name attribute on the <map> element, which you are about to meet, preceded by a pound or a hash sign. The <map> element actually creates the map for the image and usually follows directly after the <img /> element. It acts as a container for the <area /> elements that actually define the clickable hotspots. The <map> element carries only one attribute, the name attribute, which is the name that identifies the map. This is how the <img /> element knows which <map> element to use. The <area> element specifies the shape and the coordinates that define the boundaries of each clickable hotspot. The following code combines imagemaps and JavaScript to produce a message in a text box when the mouse is moved over different parts of an image. <html> <head> <title>Using JavaScript Image Map</title> <script type=”text/javascript”> <!– function showTutorial(name) { document.myform.stage.value = name } // –> </script> </head> <body> <form name = “myform”> <input type = “text” name = “stage” size = “20” /> </form> <!– Create Mappings –> <img src = “//images/usemap.gif” alt = “HTML Map” border = “0” usemap = “#tutorials”/> <map name = “tutorials”> <area shape = “poly” coords = “74,0,113,29,98,72,52,72,38,27” href = “/perl/index.htm” alt = “Perl Tutorial” target = “_self” onMouseOver = “showTutorial(”perl”)” onMouseOut = “showTutorial(””)”/> <area shape = “rect” coords = “22,83,126,125” href = “/html/index.htm” alt = “HTML Tutorial” target = “_self” onMouseOver = “showTutorial(”html”)” onMouseOut = “showTutorial(””)”/> <area shape = “circle” coords = “73,168,32” href = “/php/index.htm” alt = “PHP Tutorial” target = “_self” onMouseOver = “showTutorial(”php”)” onMouseOut = “showTutorial(””)”/> </map> </body> </html> The following output is displayed on successful execution of the above code. You can feel the map concept by placing the mouse cursor on the image object. Print Page Previous Next Advertisements ”;