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”;
Little Angel Baby Easy Dry Diaper Pants With 12 Hrs Absorption Large Size, 9-14 Kgs - L (62 Pieces)
₹499.00 (as of April 10, 2026 13:48 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 Natural Soft Premium Baby Diaper Pants, Our No.1 Soft Pants, Medium (M) Size (7-12 Kgs), Pack of 60 diapers | Cloud Softness All over with India's 1st Cloud Touch BeltTM
₹716.00 (as of April 10, 2026 13:48 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.)GLUN® Premium 6 Piece Cute Printed Babies Bibs Different Colour, Waterproof & Washable Feeding Bibs for Infant Kids to Toddler 8-24 Months
₹179.00 (as of April 10, 2026 13:48 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.)Hands Free Breast Pump, Wearable Breastfeeding Pump, Lightweight Portable Electric Pump 4 Modes & 12 Suction Levels, Comfortable & Low Noise, 24mm Flange, 1 Pack Pink (VERTICAL)
₹799.00 (as of April 10, 2026 13:48 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.)Himalaya Gentle Baby Wash 400ml | No tears formula |with chickpea and Green gram| Cleansing baby's gentle skin
₹241.00 (as of April 10, 2026 13:48 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.)Toddlyy 10 Pcs Silicone Baby Self Feeding Set for Toddlers 6+ Months | Baby Led Weaning Self Feeding Kit | Suction Plate & Bowl, Bib, Cup, Spoon & Fork, Fruit Feeder, Finger Brush | FDA | Feee Ebook (Green)
₹849.00 (as of April 10, 2026 13:48 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.)Washable Reusable Baby Cloth Diaper Set 5 | Premium Fabric, Adjustable Size, Waterproof Pocket Nappy Without Insert | Soft & Skin Friendly Baby Diapers for Infants & Toddlers (Pack of 5)
₹499.00 (as of April 10, 2026 13:48 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.)Kidbea Wide Neck Steel Baby Feeding Bottle 250ml | Anti-Colic, BPA Free, Milk Feeder with Nature Flow Soft Silicon Nipple
₹299.00 (as of April 10, 2026 13:48 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.)Blushbaby Pack of 6 Pure Cotton Padded Nappy for Newborn Baby 0–3 Months | Double Layered, Extra Soft & Breathable Cotton Langot | Reusable & Washable Cotton Nappy for Baby Boy & Girl | Newborn Baby Essentials
₹359.00 (as of April 10, 2026 13:48 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.)Zivvy Pink Play Gym for Babies 0 to 18 Months | Play Mat with Tummy Time Hanging Toys for Newborn | Floor Mat for Kids Playing | Infant Toys for 0 to 6 to 18 Months | New Born Baby Essentials & Gifts
₹549.00 (as of April 10, 2026 13:48 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.)Dell MS116 Wired Mouse, 1000 DPI, Scrolling Wheel, 2 Buttons, 1 x USB, Optical LED Tracking, Plug and Play, Scrolling Wheel, Black
₹299.00 (as of April 10, 2026 17:47 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.)ProElite Smart Case for iPad (A16) 11th/10th Generation (2025/2022) [Auto Sleep/Wake Cover] [Pencil Holder] [Soft Flexible Case] Recoil Series for Apple iPad 10th/11th Gen - Dark Blue
₹529.00 (as of April 10, 2026 17:47 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.)Apple iPad 11″: A16 chip, 27.69 cm (11″) Model, Liquid Retina Display, 128GB, Wi-Fi 6, 12MP Front/12MP Back Camera, Touch ID, All-Day Battery Life — Blue
Now retrieving the price.
(as of April 10, 2026 17:47 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.)