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

​Learn JavaScript - Free Course for Beginners
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.
5 min read
JavaScript Course Understanding Code Structure in JavaScript
Inserting JavaScript into a webpage is much like inserting any other HTML content. The tags used to add JavaScript in HTML are &lt;script&gt; and &lt;/script&gt;. The code surrounded by the &lt;script&gt; and &lt;/script&gt; tags is called a script blog. The 'type' attribute was the most important attribute of &lt;script&gt; tag. However, it is no
4 min read
Introduction to JavaScript Course - Learn how to build a task tracker using JavaScript
This is an introductory course about JavaScript that will help you learn about the basics of javascript, to begin with, the dynamic part of web development. You will learn the basics like understanding code structures, loops, objects, etc. What this course is about? In this course we will teach you about the basics of the scripting language i.e) Ja
4 min read
JavaScript Course Loops in JavaScript
Looping in programming languages is a feature that facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true. For example, suppose we want to print “Hello World” 10 times. Example: In this example we will print the same things, again and again, to understand the work of Loops. &lt;script&gt; cons
4 min read
JavaScript Course Logical Operators in JavaScript
logical operator is mostly used to make decisions based on conditions specified for the statements. It can also be used to manipulate a boolean or set termination conditions for loops. There are three types of logical operators in Javascript: !(NOT): Converts operator to boolean and returns flipped value &amp;&amp;:(AND) Evaluates operands and retu
3 min read
JavaScript Course What is JavaScript ?
JavaScript is a very famous programming language that was originally started in the year of 1995 with the motive of making web pages alive. It is also an essential part of the web developer skillset. In simple terms, if you want to learn web development then learn HTML & CSS before starting JavaScript. HTML: HTML is used to create the structure of
3 min read
JavaScript Course Operators in JavaScript
An operator is capable of manipulating a certain value or operand. Operators are used to performing specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands. In JavaScript, operators are used for comparing values, performing arithmetic operations, etc. There are various operators
7 min read
JavaScript Course Functions in JavaScript
Javascript functions are code blocks that are mainly used to perform a particular function. We can execute a function as many times as we want by calling it(invoking it). Function Structure: To create a function, we use function() declaration. // Anonymous function function(){ // function...body } // function with a name function displayMessage(){
4 min read
JavaScript Course Variables in JavaScript
Variables in JavaScript are containers that hold reusable data. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. In JavaScript, all the variables must be dec
4 min read
JavaScript Course Conditional Operator in JavaScript
JavaScript Conditional Operators allow us to perform different types of actions according to different conditions. We make use of the 'if' statement. if(expression){ do this; } The above argument named 'expression' is basically a condition that we pass into the 'if' and if it returns 'true' then the code block inside it will be executed otherwise n
3 min read