DEV Community

Guru prasanna
Guru prasanna

Posted on

Javascript - Introduction

Javascript:

--> JavaScript is the world's most popular programming language.

--> JavaScript is the programming language of the Web.

--> JavaScript is easy to learn.

--> Dynamically typed programming language.

--> JavaScript (JS) is a cross-platform, object-oriented programming language used by developers to make web pages interactive.

Image description

Why should we Study JavaScript?

--> JavaScript is one of the 3 languages all web developers must learn:

  1. HTML to define the content of web pages (Structure)

  2. CSS to specify the layout of web pages (style)

  3. JavaScript to program the behavior of web pages (Functionality)

--> JavaScript is supported by almost all browsers.

Refer:https://www.w3schools.com/js/

Javascript is used in:

  • Web Development
  • Frontend and Backend Development
  • Game Development
  • Desktop Applications
  • Real-Time Applications
  • AI and Machine Learning

How to use javascript?

a) Internal javascript
b) External javascript

Internal and External JavaScript are the two ways of adding JavaScript code to an HTML document.

a) Internal JavaScript

Internal JavaScript refers to embedding JavaScript code directly within the HTML file using <script> tag, either inside the <head> or <body> tag. This method is useful for small scripts specific to a single page.

b) External javascript

External JavaScript is when the JavaScript code written in another file having an extension .js is linked to the HMTL with the src attribute of script tag.

Syntax:
<script src="url_of_js_file"> </script>

JavaScript Functions and Events:

--> Function is a block of JavaScript code, that can be executed when it is "called" for.

--> Function is a set of instructions or block of reusable code to perform specific task with a name.

--> Function is defined using function keyword.

For example, a function can be called when an event occurs, like when the user clicks a button.

Event: An event is an action or occurrence that happens in the browser.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Javascript</title>
    <script>
        function payilagam(){
            document.getElementById("welcome").innerHTML = "Welcome to Payilagam";
        }
    </script>
</head>
<body>
    <h1 id="welcome"></h1>
    <button onclick="payilagam()">Click Me</button>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Top comments (0)