JavaScript

Last Updated : 11 Jan, 2024

JavaScript (JS) is the most popular lightweight, interpreted compiled programming language. It can be used for both Client-side as well as Server-side developments. JavaScript also known as a scripting language for web pages.

JavaScript Tutorial
 

Reason to Learn JavaScript

JavaScript is used by many developers (65% of the total development community), and the number is increasing day by day. JavaScript is one such programming language that has more than 1444231 libraries and increasing rapidly. It is preferred over any other programming language by most developers. Also, major tech companies like Microsoft, Uber, Google, Netflix, and Meta use JavaScript in their projects.

JavaScript can be added to your HTML file in two ways:

  • Internal JavaScript
  • External JavaScript

 

Internal JavaScript: We can add JS code directly to our HTML file by writing the code inside the <script> & </script>. The <script> tag can either be placed inside the <head> or the <body> tag according to the requirement.

Example: It is the basic example of using JavaScript code inside of HTML code, that script enclosing section can be placed in the body or head of the HTML document.

HTML

<!DOCTYPE html>
<html lang="en">

<head>
    <title>
        Basic Example to Describe JavaScript
    </title>
</head>

<body>

    <!-- JavaScript Code -->
    <script>
        console.log("Welcome to GeeksforGeeks");
    </script>
</body>

</html>

Output: The output will display on console.

Welcome to GeeksforGeeks

 

External JavaScript: We can create the file with a .js extension and paste the JS code inside of it. After creating the file, add this file in <script src=”file_name.js”> tag, and this <sctipt> can import inside <head> or <body> tag of the HTML file.

Example: It is the basic example of using JavaScript javascript code which is written in a different file. By importing that .js file in the head section.

HTML

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <title>
            Basic Example to Describe JavaScript
        </title>
        <script src="main.js"></script>
    </head>

    <body>
    </body>

    </html>
    

Javascript

    /* JavaScript code can be embedded inside
    head section or body section */
    console.log("Welcome to GeeksforGeeks");

    // JavaScript file name: main.js
    

Output: The output will display on console.

Welcome to GeeksforGeeks

JavaScript Used for

It is mainly used to develop websites and web-based applications. JavaScript is a language that can be used as a front-end as well as a backend.

  • Creating Interactive Websites: JavaScript is used to make web pages dynamic and interactive. It means using JavaScript, we can change the web page content and styles dynamically.
  • Building Applications: JavaScript is used to make web and mobile applications. To build web and mobile apps, we can use the most popular JavaScript frameworks like – ReactJS, React Native, Node.js etc.
  • Web Servers: We can make robust server applications using JavaScript. To be precise we use JavaScript frameworks like Node.js and Express.js to build these servers.
  • Game Development: JavaSCript can be used to design Browser games. In JavaScript, lots of game engines are available that provide frameworks for building games.

How JavaScript makes HTML build-website better

  • JavaScript is an advanced programming language that makes web pages more interactive and dynamic whereas HTML is a standard markup language that provides the primary structure of a website.
  • JavaScript simply adds dynamic content to websites to make them look good and HTML work on the look of the website without the interactive effects and all.
  • JavaScript manipulates the content to create dynamic web pages whereas HTML pages are static which means the content cannot be changed.
  • JavaScript is not cross-browser compatible whereas HTML is cross-browser compatible.
  • JavaScript can be embedded inside HTML but HTML can not be embedded inside JavaScript.

Things that makes JavaScript demanding

JavaScript is the most popular and hence the most loved language around the globe. Apart from this, there are abundant reasons to become the most demanding. Below are a listing of a few important points:

  • No need for compilers: Since JavaScript is an interpreted language, therefore it does not need any compiler for compilation.
  • Used both Client and Server-side: Earlier JavaScript was used to build client-side applications only, but with the evolution of its frameworks namely Node.js and Express.js, it is now widely used for building server-side applications too.
  • Helps to build a complete solution: As we saw, JavaScript is widely used in both client and server-side applications, therefore it helps us to build an end-to-end solution to a given problem.
  • Used everywhere: JavaScript is so loved because it can be used anywhere. It can be used to develop websites, games or mobile apps, etc.
  • Huge community support: JavaScript has a huge community of users and mentors who love this language and take it’s legacy forward.

Learn more about JavaScript

JavaScript Objects Complete Reference

This section contains the list of all properties and methods of all JavaScript objects.

 
 
 

Please go through our JavaScript Course and JavaScript Examples link to see the wide collection of JavaScript programming examples. The examples are categorized based on the topics, including objects, functions, arrays, DOM, and many more.

Recent Articles on JavaScript


My Personal Notes arrow_drop_up

Share your thoughts in the comments

Similar Reads