Javascript Basics

6 July 2018

How does JavaScript compare to HTML and CSS?

To me, it seems like HTML is the core structure of a website. CSS adds more colour and aesthetically pleasing functions. JavaScript is a further expansion of that, and adds interactivity while allowing the storage of data. It tells the browser how to change the web page in response to events that happen.


Explain control flow and loops using an example process from everyday life, for example 'waking up' or 'brushing your teeth'.

Code is read and executed from top down, so if the order of your code is not correct it can return different values. Control flow refers to this - the structure that code is written in. All the while, control flow checks to see if the condition is true or false, and then executes a certain code based on the boolean result. Looping is a sequence of instruction.

An everyday example: The simple act of taking a walk. You know how to move your left leg. You know how to move your right leg. Now do that repeatedly (via a loop) until you arrive at your destination.


Explain the difference between accessing data from arrays and objects.

In JavaScript, arrays are objects, just slightly modified (with a few more functions). Arrays are for numerically indexed data - for non-numeric keys, we use an Object.


Explain what functions are and why they are useful.

Functions are a set of code that can be called upon and used repeatedly. Instead of painstakingly writing the same or similar code over and over again, we can simply call a function by its name, then the computer takes over and does the repeating job.


  • HOME