Introduction to JavaScript

Filter Course


Introduction to JavaScript

Published by: Sujan

Published date: 16 Jun 2021

JavaScript - Photo

Introduction to JavaScript

JavaScript is the most popular and widely used client-side scripting language. Client-side scripting refers to scripts that run within your web browser. JavaScript is designed to add interactivity and dynamic effects to web pages by manipulating the content returned from a web server.

What You Can Do with JavaScript

There are lot more things you can do with JavaScript.

  • You can modify the content of a web page by adding or removing elements.
  • You can change the style and position of the elements on a web page.
  • You can monitor events like a mouse click, hover, etc., and react to them.
  • You can perform and control transitions and animations.
  • You can create alert pop-ups to display info or warning messages to the user.
  • You can perform operations based on user inputs and display the results.
  • You can validate user inputs before submitting them to the server.

Adding JavaScript to Your Web Pages

There are typically three ways to add JavaScript to a web page:

  • Embedding the JavaScript code between a pair of tag.
  • Creating an external JavaScript file with the .js extension and then load it within the page through the src attribute of the tags. The

     

    This is useful if you want the same scripts available to multiple documents. It saves you from repeating the same task over and over again and makes your website much easier to maintain.

    Well, let's create a JavaScript file named "hello.js" and place the following code in it:

    // A function to display a message function sayHello() { alert("Hello World!"); } // Call function on click of the button document.getElementById("myBtn").onclick = sayHello;

    Now, you can call this external JavaScript file within a web page using the