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”;
Jr. Sr. Baby Diaper Pants with Advanced Leak Protection | Soft & Comfortable| Medium | 7-12 Kg | 72 Counts | Pack of 1
₹459.00 (as of July 14, 2025 22:39 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 Hooded Baby Bath Towel for New Born | Wash Cloth, Quick Absorbent, Used for Baby Swaddling, Extra Soft Cotton Towels for Kids/Toddlers/Infants/Babies, Pack of 1, (Blue Deer/Elephant) 80X80 CM
₹430.00 (as of July 14, 2025 22:39 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.)Little's Soft Cleansing Baby Wipes with Lid | 80 Wipes x Pack of 3 - 240 Wipes | Extra Thick & Moist Wet Wipes for Baby's | Prevents Rashes & Redness with Goodness of Aloe Vera, Vitamin E & Jojoba Oil
₹215.00 (as of July 14, 2025 22:39 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.)Mini Wonders Baby Gym Play Mat with Hanging Toys | Tummy Time Activity Gym for Newborns | Soft Mat with Rattles & Mirror | Sensory Development Toy 0-12 Months
₹521.00 (as of July 14, 2025 22:39 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 Powder For Baby, 700G
₹315.00 (as of July 14, 2025 22:39 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.)PLIX - THE PLANT FIX Happy Hair Gentle Shampoo for gentle cleansing | Nourished & soft hair | soothes the scalp | moringa seed oil, argan oil & aloe vera | daily use | for 2 years & above kids
₹449.00 (as of July 14, 2025 22:39 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.)MamyPoko Pants All Night Absorb Baby Diapers, Large (L), 44 Count 9-14 kg
₹332.00 (as of July 14, 2025 22:39 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.)StarAndDaisy Baby Head Protection Helmet for Crawling Walking Baby Head Protector - Head Protection for Care 6 Months - 2 Years Soft Cushion Headguard, Toddler Helmets - Grey
Now retrieving the price.
(as of July 14, 2025 22:39 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.)