There are many different tools inside JavaScript that can be used to help create a webpage. Outlined below are some of the different tools that can be useful when creating with JavaScript.
Functions allow a webpage to execute a single action, or multiple actions. It is broken down into 3 main parts, the keyword, the name, and the action. Here's an example of a simple function:
function hello(){
console.log ("Hello World!")
}
So when this action is "called," the result will be "Hello World!" To call the function the code is:
hello();
For Loops are helpful when pulling multiple blocks of code until a condition is met. A For Loop consists of a variable, a condition, an action, and the call. The easiest way to show this is by using numbers. Below is an example of a For Loop that counts from 0 to 10.
for (var i = 0; i <= 10; i +=1){
console.log(i)
}
When this For Loop is performed, the result will list out 0-10 individually.
Arrays are useful in that they allow the user to store multiple valuables within a single variable. An array has a 2 main elements and can be easily identified by the use of square brackets. See the array below:
var colors = ['red', 'orange', 'yellow',
'blue', 'indigo', 'violet']
An array is nice in that individual values can be pulled from it. Each color in the above array is assigned an index number automatically. The index number of an array always starts at 0, so red is assigned to 0, orange to 1, etc. If I want to pulled specifically indigo listed in the above array, I would use:
console.log(colors[4]);