Javascript

IN500WORDS

Javascript is one of the most popular programming languages in the world. ‍‍While its most common application is to make websites interactive and fun, its uses are somewhat endless.‍‍

Every time you access a website on your computer, a server sends you a html file. This will probably include some css and 98% of the time javascript.

We can write javascript inside a html file using the script tag. Or we can link to a separate .js file.

In essence, javascript is not unlike any language you might speak. It is made up of a series of statements, and semicolons to break up these statements.

Let's start by looking at variables. Variables are place holders for information. Think of a variable as a container, we can put things (values) inside a container and then we can label that container. This makes our code simpler, intuitive to read and makes repeated values easy to change. We can define variables as numbers, strings, which are a sequence of characters commonly letters, or boolean values.

Strings have methods. Lets use the substring method as an example as most methods work the same as this. A substring method is where we can take two index values of a string and return the portion that lies between them.

We can write a comment using two forward slashes. // Comments are extremely useful reminders for what's going on in our code.

Operators are what you learnt in year 3, addition +, subtraction -, multiplication * and division /.‍‍Arrays are like variables that hold multiple values at once. Think of a shopping list. Tuesday's list is the label, while all the different things you need to buy are the values inside the shopping list array.

Functions are useful for when you have pieces of code you want to use again. We can put code inside a function and call it whenever we need. Think of functions as a recipe. The series of steps you need to make a cake would be the code but all you need to search for in your recipe book is chocolate cake.

Conditional statements allow us to execute a piece of code when a particular condition is met. We have the condition, and then the code that we want to execute should this condition be met. If your cat is at the door, take the necessary steps to open the door… else keep your door closed.

Loops are like conditional statements we want to repeat multiple times. Thus we have our condition that needs to be met to execute the code, code that will run, and now we can add a condition for when to stop running this code.Events are actions the user can do on a webpage, such as clicking or scrolling. Using the DOM or document object model, a virtual representation of the structure of our html file we can listen to these events. and attach functionality to them. For example if a user scrolls we could change the background colour.