What is JavaScript?

What is JavaScript?

JavaScript is a Programming Language mostly used to make web pages interactive. It gives the page life and, most of the time, is behind the interactive elements and animations on a site. JavaScript, HTML and CSS work very well together. HTML provides the Structure of page, CSS the Styles and JavaScript the Interactive Elements and Animations.


Brief History

JavaScript was developed in 1995 by Brendan Eich. The original name was Mocha, it was then changed to LiveScript 4 months later, then another 3 months after that, the name was changed to JavaScript.

All web pages were static when the World Wide Web was first created in the early 1990s. You saw exactly what the page was setup to show you, and there was no way for you to interact with it. Being able to interact with a web page to have it do something in response to your actions would require some form of programming language to “instruct” the page how it should respond. In order to have it respond immediately without having to reload the web page, this language needed to be able to run on the same computer as the browser displaying the page. Which is where JavaScript came into play.


Why use JavaScript?

JavaScript can be used for many things. The main use is to provide Animation and Interaction to certain elements on a Webpage. A good example of this is if you have forms on your site, the forms will need to be checked over to see if it is ‘valid’ before it can be processed. JavaScript can do this for you, if you have ever filled in a form and received an error such as: ‘This isn’t a valid email’ or ‘Passwords do not match’ then this is most likely JavaScript.

Another great use of JavaScript is if your site features a Slideshow. In order for the Slideshow to function without JavaScript, the next and previous buttons that work the slideshow would need to refresh the entire page to load the new image. JavaScript can be used to load and replace the images in the slideshow.



Variables in JavaScript can be thought of as named containers. You can place data into these containers, then refer to the data by simply naming the container. Variables are declared by the var keyword. An example of a variable could be var x = 5; which means the variable ‘x’ equals 5. A lot like algebra.


Assignment Statements

There are lots of different Assignment Statements that are used to assign values to Variables.

= (x = y),

+= (x += y is the same as x = x+y)

-= (x -= y is the same as x = x-y)

*= (x *= y is the same x = x*y)

/= (x /= y is the same as x = x/y)


Data Types

JavaScript has 3 main Data Types. These are: Numbers (123, 5.6), Strings (“Some Text”, “This is a String”) and Booleans (True or False).



Often in code, you’ll want to write code depending on different decisions. This is where you can use:

‘if’ – if (time < 12) { greeting = "Good Morning";} If Statements, basically mean if this, do this.

‘elseif’ –  elseif (time < 17) { greeting = "Good Day"; } basically another if statement.

‘else’ else { greeting = "Good Evening"; } else conditions mean, if anything else, do this.

A real life example of these conditionals could be:

  1. IF the door is locked, THEN unlock the door, ELSE do nothing (go to next instruction)
  2. IF the door is closed, THEN open the door, ELSE do nothing
  3. Enter the room
  4. IF the room is dark, THEN switch on the light, ELSE do nothing
  5. Close the door behind you

Image from BBC Bitesize



Sometimes in code, you’ll want something to happen over and over again. This is where loops are used.

While Loop – This is where a Block of code is run repeatedly while something is true.
counter = 1; while (counter < 10 ) { counter += 1; } would keep adding 1 to the counter until it reaches 10.

DoWhile Loop – Similar to the While Loop but the code will run at least once whereas the While Loop may not run at all.
var condition = false; do{ console.log ("This will run once!"); } while (condition = true);

For Loop – The for loop is made up of 3 expressions in brackets, separated by semi-colons, followed by a statement. for var i = 0; i < 9; i++){ console.log(i); }would set the variable i to 0. Then it checks that i is less than 9, then adds 1 each time. Then displays i.

A Diagram of this is:

Do While

Image from BBC Bitesize



Arrays allow you to assign more than one value to a variable e.g.
var fruits = ["apple", "orange", "mango" ]; would assign Apple, Orange and Mango to the Fruits Variable.



A function is a piece of code that can be called anywhere throughout the program, which saves you writing something again and again. function sayHello() { alert ("Hello There!"); } creates the function ‘sayHello’. This can then be called anytime throughout the code.


Advantages and Disadvantages of JS


  • JavaScript is executed on the Client Side. This means that the code is executed on the user’s processor instead of the web server, which saves Bandwidth and Strain.
  • Not too hard to learn. JavaScript isn’t too difficult to learn and uses syntax that is quite close to English.
  • Speed. As the code is executed from the user’s computer, processing is completed almost instantly depending on the task.


  • Security Issues. As the code is executed from the Users computer, in some cases this can be exploited for Malicious Purposes.
  • Support/Compatibility. JavaScript is not supported by all browsers. This is mainly only older browsers so shouldn’t be a problem to most people.
  • Outdated. JavaScript is a very old Scripting Language and is beginning to become a little outdated. There are now other, more modern languages that can do the same thing such as JQuery.


Closing Thoughts

JavaScript is a vital Language that can do many things. It is very important in the Front-End build of sites as it allows sites to come to life. It does however have Positives and Negatives just like any other Programming Language. It is all basically down to your own personal preference.