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”;
BeyBee Waterproof Quick Dry Sheet for Baby| Bed Pad Anti-Piling Fleece Extra Absorbent Washable Matress Protector| Baby Bed Protector Sheet for Toddler Children, Large Size, 140x100cm, Grey
₹399.00 (as of March 17, 2025 22:27 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 Large L Size Premium Feather Diaper for Baby 9 to 14 kgs (24 Pack Offer)
₹476.00 (as of March 17, 2025 22:27 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.)Novo Baby Rai Mustard Seeds Pillow with Lavender, Baby-Round Head Shaping Baby Pillow,Neck Support Pillow Gifting 0-12 Months (Green)
₹339.00 (as of March 17, 2025 22:27 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.)Aveeno Baby Daily Moisture Hydrating Facial Gel (Cream) 60g I Ultra-light| 24 hours moisturisation Face cream| Triple oat extract & avocado oil I Paediatrician recommended I Newborn, infants & children
₹939.00 (as of March 17, 2025 22:27 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 Disposable Diaper Bags With Dispenser, Waste Bags 4 Refill Rolls/60 Bags, Convenient and Quick Diaper Disposal, Unscented Leak & Odors Proof Diaper Trash Bags (4 Roll) (4 Roll + Case)
₹275.00 (as of March 17, 2025 22:27 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.)Wearable Hands Free Electric Breast Pump for Feeding Mothers, Automatic Hands-Free Pumping Machine with 4 Modes & 9 Suction Levels,Effective & comfortable, Portable & built-in rechargeable battery, easy to use and clean.Automatic Flovtrix Electric Breast Pump for Newborn Baby Feed.
₹1,399.00 (as of March 17, 2025 22:27 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.)WOWPER FRESH PANT DIAPER NEW BORN 80 DIAPERS - NB (80 PIECES)
Now retrieving the price.
(as of March 17, 2025 22:27 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.)