What is JavaScript?
JavaScript is a programming language that adds interactivity to your website (for example: games, responses when buttons are pressed or data entered in forms, dynamic styling, animation).
JavaScript (“JS” for short) is a full-fledged dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites.
Importance of JavaScript?
- An HTML page is a static one and without JavaScript it would be static still.
- JavaScript could make a web page dynamic and also we can create special effects on web pages like rollover, roll out and many types of graphics that would leave an amazing impression on the user’s mind.
- For example, for a flash content on a web page to be executed in a web browser the JavaScript must be enabled.
- JavaScript is mainly used in all websites for the validation purpose.
- The Validation would be for a contact form or a registration form where a user fills all there information and there the page has to validate the filled data and that validation could be done with JavaScript other than server side scripting languages.
- JavaScript is not only supports the web pages but also it supports the external applications like PDF documents, running widgets, supporting for flash applications etc.
History of JavaScript
- Designed by Brendan Eich
- First appeared May 23, 1995; 21 years ago
- Developer : Netscape Communications Corporation, Mozilla Foundation, Ecma International
- Current version : ECMAScript
- URL : https://www.javascript.com/
Basic Structure of JavaScript
JavaScript can be placed in the <body> and in the <head> section of any HTML page.
- The <script> Tag
<script>
document.getElementById(“demo”).innerHTML = “My First JavaScript”;
</script>
- JavaScript in <body>
<!DOCTYPE html> <html><body> <h1>A Web Page</h1> <p id="demo">A Paragraph</p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } </script> </body> </html>
- External JavaScript
<!DOCTYPE html> <html> <body> <script src="javascript.js"></script> </body> </html>
File Extension of JavaScript
- JavaScript files have the file extension .js.
Comment Line in JavaScript
- Single Line Comments
Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
Example
// Change heading:
document.getElementById(“myH”).innerHTML = “My First Page”;
- Multi-line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
Example
/*
The code below will change
the heading with id = “myH”
and the paragraph with id = “myP”
in my web page:
*/
document.getElementById(“myH”).innerHTML = “My First Page”;
document.getElementById(“myP”).innerHTML = “My first paragraph.”;
Variable Declaration
- Declaration: The variable is registered using a given name within the corresponding scope (explained below – e.g. inside a function).
- Initialization: When you declare a variable it is automatically initialized, which means memory is allocated for the variable by the JavaScript engine.
- Assignment: This is when a specific value is assigned to the variable.
Syntax:
var x; // Declaration and initialization
x = “Hello World”; // Assignment
// Or all in one
var y = “Hello World”;
Pampers Active Baby Tape Style Diapers, Large (L) Size, 78 Count, Adjustable Fit with 5 star skin protection, 9-14kg Diapers
₹1,499.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Oasis Baby 100% Breathable Cotton Feeding/Nursing Apron With Pocket | Adjustable Neck Strap | Tie Back | Breastfeeding and Multipurpse Cloth - Pack of 1
₹299.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Supples Premium Diapers, X-Large (XL), 54 Count, 12-17 Kg, 12 hrs Absorption Baby Diaper Pants
₹525.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Luem - above the best Baby Helmet for Crawling Walking Baby Head Protector - Head Protection for Infant Baby No Bumps and Soft Cushion Safety Headguard I Toddler Inflatable Helmets (Blue)
₹199.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)R for Rabbit Tritan Dino 320ml Baby Straw Sipper for Kids | Twin Handle Non Toxic BPA Free Soft Silicone Straw Sippy Bottle | Leak Proof Drinking Sippy Cup for 12+ Months Babies (Yellow Blue)
₹596.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)R for Rabbit Waterproof Quick Dry Sheet for Baby | Anti-Piling Fleece Extra Absorbent Instant Dry Sheet for Baby Bed | Baby Cot Protector sheet | Baby Bed Protector (Size-S,Green-Grey,Pack Of 2 Combo)
₹295.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Philips Avent Natural Response Baby Bottle - 260ml Baby Milk Bottle, BPA Free for Babies 1 Month (260ml Giraffe Print)
₹629.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Philips Avent Anti-Colic Baby Feeding Bottles by Fratelli | 9oz/260ml - Pack of 1 | SCY103/10
₹399.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Pampers All round Protection Pants Style Baby Diapers, XX-large (XXL) Size, 42 Count, Anti Rash Blanket, Lotion with Aloe Vera, 15-25kg Diapers
₹965.00 (as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Panda Baby Products Baby Walker with Musical Toy Bar Rattles and Activity Toys Green Colour
Now retrieving the price.
(as of April 28, 2024 00:10 GMT +05:30 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)