Javascript Introduction

Getting started with Javascript


JavaScript is a popular programming language that powers many devices and web frameworks. It is also used in backend technologies and is the first choice for developers in today's world. Because it's widely used, you can utilize JavaScript in different ways: 1. With HTML, where you include JavaScript within script tags and use it. 2. With Node.js: By installing Node.js, it provides a runtime console where you can execute JavaScript. 3. Or with a browser. Nowadays, browsers are very powerful, allowing you to run JavaScript in every browser console.

1. With HTML, where you include JavaScript within script tags and use it.

1. First, create a folder. In our case, I am creating a folder named "Learn JS". 2. Create an HTML file named index.html and include the script at the bottom of the body, for example.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript Example</title>
</head>
<body>
    <h1>JavaScript Example</h1>

    <!-- Script tag with src attribute to include external JavaScript file -->
    <script src="script.js"></script>
</body>
</html>

3. Now, create a JavaScript file named "script.js". 4. Next, write some dummy code in the JavaScript file, like this:

// Contents of script.js
alert("Hello, world!");

5. Now, open the HTML file in any browser by double-clicking it. This action will launch and run your JavaScript file.

2. With Node.js: By installing Node.js, it provides a runtime console where you can execute JavaScript.

Node.js is a backend runtime environment for JavaScript code. 1. First, you have to install the latest version of Node.js depending on your machine. 2. Open the terminal. If you're on a Windows machine, open Command Prompt or PowerShell. 3. Type "node". This will open the Node.js environment, where you can execute any Node.js commands, and they will work as expected.

3. Or with a browser. Nowadays, browsers are very powerful, allowing you to run JavaScript in every browser console.

Open any browser that supports JavaScript. 1. Press F12 or right-click anywhere on the page and choose "Inspect". 2. This action will open the browser's developer tools. 3. In the developer tools window, navigate to the "Console" tab. 4. Here, you can write any JavaScript code directly into the console. Press Enter to execute the code, and you'll see the output or any errors directly in the console.