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”;
Amazon Brand - Supples Premium Baby Diaper Pants | 72 Baby Diapers | Medium | 7-12 Kg | 12 Hrs Absorption | Cushiony Cotton Soft Fabric | Phthalates-Free | Triple Leak Guard
₹519.00 (as of February 16, 2026 04:20 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.)Amazon Brand - Supples Premium Baby Diaper Pants | 62 Baby Diapers | Large | 9-14 Kg | 12 Hrs Absorption | Cushiony Cotton Soft Fabric | Phthalates-Free | Triple Leak Guard
₹495.00 (as of February 16, 2026 04:20 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.)Portable Warmer Bottle,Travel-Friendly,Fast-Heating,Cordless And Rechargable,Precise Temperature Control,Long-Lasting Warming UP to 5Hour,Comfortable Feeding Bottle For Home And Outdoor(bottle not included) (A-1)
₹1,499.00 (as of February 16, 2026 04:51 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.)Huggies Complete Comfort Wonder Pants | Pant Style Baby Diapers Extra Large Size (XL), 56 Count | India's Fastest Absorbing Diaper, Prevents Diaper Rash, Ideal for 12 to 17 Kgs
₹694.00 (as of February 16, 2026 04:20 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.)Mee Mee Wet Wipes for Baby Skin with Aloe Vera | 72 Wipes x Pack of 3-216 Wipes | Paraben Free, Fragrance Free, pH Balanced, Dermatologically Safe, Baby Wipes Combo | Pack With Lid
₹199.00 (as of February 16, 2026 04:20 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.)Claudelle Steering Wheel Toy Simulate Driving Car Copilot Steering Wheel Electric Baby Toys with Sound Driving Vocal Toy Kids Musical Educational Stroller Color (YELLOW)
₹429.00 (as of February 16, 2026 04:51 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.)Prplet Baby Diaper Organizer Caddy Baskets – Large Nursery Storage Basket with Handles, Removable Dividers & Multiple Compartments | Diaper Bag for New born Essentials, Toys, Wipes, Bottles (Green)
₹799.00 (as of February 16, 2026 04:51 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.)HomeVera Corner Protector for Baby (Pack of 4) ? Soft Transparent Table Corner Guards & Edge Protectors for Sharp Edges, Furniture & Bed Corners ? Baby Proofing Safety Set for Kids & Toddlers
₹94.00 (as of February 16, 2026 04:51 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.)Baby Sleeping Support Pillow with Side Rollers | Newborn Safety Sleeping Pillow Set | Soft Cotton Infant Neck Pillow for 0–12 Months | Anti-Flat Head Cushion for Baby Boys & Girls (Light Blue)
₹277.00 (as of February 16, 2026 04:51 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 Happy Sleep Pant Style Baby Diapers, Large (L), 42 Count, 1 Pampers = 1 Night Sleep, with Anti Rash Shield, 9-14 Kg Diapers
₹459.00 (as of February 16, 2026 04:20 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.)OnePlus Pad Lite with Biggest Battery in Segment 9340 mAh, 11"(27.94 cm) Display with 500 nits Brightness & 11 Hrs of Video Playback, 8GB RAM 128GB Storage, LTE, Aero Blue
Now retrieving the price.
(as of February 16, 2026 11:12 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.)