JavaScript

JavaScript

JavaScript, often abbreviated as JS, is a programming language and core technology of the Web, alongside HTML and CSS. 99% of websites use JavaScript on the client side for webpage behavior.

Web browsers have a dedicated JavaScript engine that executes the client code. These engines are also utilized in some servers and a variety of apps. The most popular runtime system for non-browser usage is Node.js.

JavaScript is a high-level, often just-in-time compiled language that conforms to the ECMAScript standard. It has dynamic typing, prototype-based object-orientation, and first-class functions. It is multi-paradigm, supporting event-driven, functional, and imperative programming styles. It has application programming interfaces (APIs) for working with text, dates, regular expressions, standard data structures, and the Document Object Model (DOM)

The ECMAScript standard does not include any input/output (I/O), such as networking, storage, or graphics facilities. In practice, the web browser or other runtime system provides JavaScript APIs for I/O.

Although Java and JavaScript are similar in name, syntax, and respective standard libraries, the two languages are distinct and differ greatly in design.

See JavaScript on Wikipedia.

Getting started

The Pro Linux Container of Brap is pre-configured with JavaScript via Node.js. Node.js allows us to run JavaScript anywhere, such as in the server-side (Back-end) via the terminal, whereas in the past, we could only run JavaScript in the client-side (Front-End) via a web browser.

To run JavaScript expressions in the Terminal, go to your Node.js prompt:

node
let greeting = "Hello, World!"
console.log(gretting)

To exit the Node.js prompt, press CTRL + C.

Javascript in VS Code terminal

Screenshot: Hello, World! in JavaScript running in the terminal

To create a site with JavaScript, create an index.html file with JavaScript:

<html>
<head>
    <title>Basic HTML site with JavaScript</title>
</head>
<body>
    <h1>Basic HTML site with JavaScript</h1>
    <p id="greeting"></p>
    <script>
        document.getElementById("greeting").innerHTML = "Hello, World!";
    </script>
</body>
</html>

Serve the static site via NPM serve and access it in the web browser:

serve

Javascript in browser

Screenshot: JavaScript running in the web browser

You may also use the Live Server VS Code extension by clicking the Go Live in the Status Bar:

Javascript via Live Server VS Code extension

Screenshot: Javascript via Live Server VS Code extension

Keywords

  • JavaScript
  • JS
  • web
  • front-end

Back to top