Introduction to JavaScript
JavaScript is the programming language used by front-end web developers to instruct the browser to add behaviors to the web page. It provides many programming components like variables, functions, loops, and conditions to implement instructions for the browser. Using these components, JavaScript can instruct the browser to change the content and styles of HTML documents or interact with the webserver upon receiving events generated by the user's interaction with the browser user interface.
Think about the web applications like Facebook that you use every day. They are very interactive with users. The secret behind designing such interactive web applications is JavaScript.
The figure below shows the difference between HTML, CSS, and JavaScript using the analogy of a building. A building has a structure (e.g., how many rooms and what type), decorations (e.g., floor tiling and bricked walls), and functions (e.g., serving food to the customers). Similarly, HTML describes the structure (e.g., what web content - title, image, paragraph, etc.) of the web page to the browser, CSS describes the styling (e.g., color and position), and JavaScript adds behaviors (e.g., display a list of items when the user hovers mouse over the menu).
Code :-
I<html>
<head>
</head>
<body>
<input type="text" id="inputId" placeholder="Enter Name">
<button onclick="submitForm()"> Submit </button>
</body>
</html>
Output :-
The above HTML code gets the user's name as an input using <input> tag and provides a submit button. A JavaScript function named submitForm() calls if the user clicks the submit button. This function instructs the browser to display an alert window with the text "Congratulations <user's name> !".
Written by: W.A. Eranga Dewmini