Home

Javascript Basics

How does JavaScript compare to HTML and CSS?

Javascript is quite different to HTML and CSS. HTML provides the content and structure, CSS provides styling and Javascript powers the interactive parts of a website. For example, Javascript could be used for a block of rotating images, or for a menu that pops up when clicked.

what are loops and control flow?

Control flow is the order in which instructions in code execute. Loops are a way to manipulate control flow, according to variables. Two important types of control flow are if/if else statements, and for loops. If statements show a series of choices, and how to respond if a choice is made. For loops give information about when to start and end actions. For example: Reading. FOR(start reading at page zero; read until you are bored) IF (you see an interesting quote) {write it down} ELSE IF (you don't like this book) {tear out the page}. Control flow is a means for a computer to decide how to respond to a variety of different user choices.

What's the difference between accessing data from arrays and object literals?

Object literals and arrays are both ways of holding collections of data. Data inside an array is contained in square brackets. Each piece of data has an assigned number, referring to its position inside the array. The numbering starts at zero, so the first piece of data would be at the index zero. You can access this data with arrayName[0].

An object literal is contained inside curly brackets. The data inside is expressed in pairs of properties and values. For example, for an object myDog, a property could be 'Name' and value could be 'Tommy' (which is his name). Objects don't use assigned numbers to access pieces of data inside. Instead we could use either myDog.name or myDog["name"] to access properties. Objects can also have functions asigned to them, which makes them a useful way to hold data.

What are functions and why are they useful?

A function is a block of code that executes some kind of task. They are the way you make your website interactive. They are very useful for tasks that you will need to use multiple times throughout your code, because instead of rewriting the command every time you need it, you can just call the function. This takes less time, and stops you from repeating yourself.