JavaScript Introduction:
- JavaScript performs Client-side validations
- JavaScript provides Functionality to web pages.

- JavaScript executes with HTML code.
- JavaScript is case-sensitive language
We can Write JavaScript code in places of HTML document
- Inline JavaScript
- Internal JavaScript
- External JavaScript
We can Write JavaScript code in places of HTML document
- In Body Location(Inline JavaScript)
- In Head Location(Internal JavaScript)
- External JS File
Body Location: Execute Script when web page is loading.
<html> <body> <script> alert(“Alert box while loading page”); </script> </body> </html> |
Head Location: Execute Script on action (for example click on button).
<html> <head> <script> function run(){ alert(“Alert when we click on button”); } </script> </head> <body> <button onclick=”run()”>Click Me</button> </body> </html> |
External JavaScript file:
web.html:
<!DOCTYPE html> <html> <head> <script type=”text/javascript” src=”mycode.js”></script> </head> <body> <button onclick=”alertMe()”>Click Me to Alert</button> <br/> <button onclick=”promptMe()”>Click Me to Prompt</button> </body> </html> |
mycode.js:
function alertMe() { alert(“It is alert box”); } function promptMe() { var name = prompt(“Enter your name : “); alert(“Hello ” + name + “, Welcome”); } |