Skip to the content.

Javascript (JS)

What is JS?

JavaScript (JS) is a programming language that allows implementation of complex things on web pages. Every time a web page does more than just sit there and display static information for the user to look at—displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, or more—you can bet that JavaScript is probably involved.

JS is a lightweight, interpreted, object-oriented language with functions, and is best known as the scripting language for Web pages, but it’s used in many non-browser environments as well both on user machines and servers. Contrary to popular misconception, JS is not “Interpreted Java”. In a nutshell, JavaScript is a dynamic scripting language supporting prototype based object construction. The basic syntax is intentionally similar to both Java and C++ to reduce the number of new concepts required to learn the language. Language constructs, such as if statements, for and while loops, and switch and try … catch blocks function the same as in these languages (or nearly so).

JS Structure

Embed or Include

JS can either embed the code directly inside an HTML file, or can be placed in a line in the HTML file that will point to the external JavaScript file. In most cases the latter is recommended.

In order to do that we add the script opening and closing tags. Between the two is where JS code resides.

Output

The first is how to interact with the JS code running in the browser. There are a number of ways JavaScript can display text for the user (output). They are:

Input

There are two ways to receive input. Neither of these are in use a lot, but they can be easily used to play around with the basics.

If confirm returned true, print “Hello World”, otherwise print “OK, I won’t print it.”

JS Variables

A variable means anything that can vary. In JS, a variable stores the data value that can be changed later on. There are three reseerved keywords to declare a variable they const, let, & var.

References:

Return

Home Page