What exactly is JavaScript?

What exactly is JavaScript?


JavaScript is a text-based programming language that allows you to construct interactive web pages on both the client and server sides. Where HTML and CSS give web pages structure and style, JavaScript delivers web pages interactive elements that keep users engaged.

Brendan Eich created JavaScript in 1995, and it became an ECMA standard in 1997. The standard’s official name is ECMA-262. The language’s official name is ECMAScript.

JavaScript is primary used as a client-side scripting language.

  • Means that most of the coding is written directly into the HTML page and parsed by the browser when the page is rendered on the client
  • Primary function is to add to the level of interactivity on what would other wise have been a static page

What is JavaScript used for?

JavaScript is one of the most widely used programming languages on the planet, and it’s used to make websites more interactive, process data, and construct numerous applications (mobile apps, desktop apps, games, and more).

Where do you put your JavaScript code?

When it comes to adding JavaScript code to your HTML files, you have a few options:

  1. Adding the JavaScript <script> tag in the <head>
<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Using JavaScript Tags</title>
	<script type="text/javascript">
	//Javascript code goes here
  • If you have that JavaScript in the of your document that means that JavaScript has to load prior to the contents of the page being visible.

2. The second option is to include the script tags in the <body> section

	<h1>JavaScript Tags Reference JavaScript that 
        is embedded in the HTML page</h1>
	<p>As an alternative you can link to external files</p>
	//Some more JavaScript code goes here
  • Placing scripts at the bottom of the element improves the display speed, because script interpretation slows down the display.

3. The third option (often the best) is to link to external JavaScript files

<script src=“myscript.js”></script>
  • You can place an external script reference in or as you like.
  • External scripts are practical when the same code is used in many different web pages.
  • JavaScript files have the file extension .js.
  • To use an external script, put the name of the script file in the src (source) attribute of a <script> tag
  • The linked external JS stylesheet keeps your JavaScript and HTML separate and makes it easier to debug and to locate code you want to modify
  • Keeps things better organised
  • You can use multiple script links in your file, if you start to get above 5 or 6 then you probably want to start to think about consolidating some of those files
  • The more script links you have in your the longer the page will take to load

Example of JavaScript

JavaScript can change HTML content.
One of many JavaScript HTML methods is getElementById(). The method returns an element with a specified value. Since element IDs are required to be unique if specified, they’re a useful way to get access to a specific element quickly.
The example below “finds” an HTML element (with id=“demo”), and changes the element content (innerHTML) to “Hello JavaScript”:

<!DOCTYPE html>
<html lang=“en”>
	<h2>What Can JavaScript Do?</h2>
	<p id="demo">JavaScript can change HTML content.</p>
	<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello       JavaScript!"'>Click Me!</button>


  • The innerHTML property sets or returns an element’s HTML content (inner HTML).
  • In most cases that you want to “display” data you will use the innerHTML property and the DOM (Document Object Model) in order to write information to the page.
    document.getElementById(“demo”).innerHTML=“Hello JavaScript”;
  • DOM is the way your JavaScript is going to interact with your HTML.
  • The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
  • .getElementById() is a method in the DOM that will grab a particular element on your webpage.

Further reading

To learn more about the DOM and DOM methods, I recommend following this link at W3Schools – JavaScript HTML DOM

Share this article. Follow me on Twitter for more updates.

Pin It on Pinterest