Course Prerequisites
Explore key JavaScript concepts such as variable declaration, function types, loops, arrays, and objects. This lesson refreshes your programming foundation to ensure you effectively work with React frontends and Meteor.js backend components.
This course assumes familiarity with the following JavaScript concepts:
- Variables
- Functions
- Function invocation
- Loops and data structure
- Basic HTML and CSS
A low-level approach is taken to explain concepts and code with a lot of hands-on practice to help developers master the concepts taught. Here’s a quick refresher on some JavaScript concepts and knowledge necessary to understand the course.
Variable declaration
A variable is used to store data in a program. It’s declared using the const or the let keyword followed by the variable’s name.
const name = "Brandon Rodgers";
let age = 23;
//variable declared with const can not be reassigned while those with let can.
Function declaration
A function is a set of statements or blocks of code that perform a particular task. A function should only perform one task. To declare a function, use the function keyword followed by the function’s name with parenthesis for the arguments. The set of instructions or statements in a function is written inside curly brackets ({})
function showName() {
return "Mikel Arteta";
}
//a function can return a value or not
Function expression
A function expression assigns a function to a variable. A function assigned to a variable doesn’t need a name. We reference it using the variable name.
const showName = function() {
return "Mikel Arteta";
}
Function invocation
We must use a function after defining it. This is done by invoking the function. A function is invoked by adding parentheses after the function name. Any arguments the function needs are added inside the parentheses.
const showName = function() {
return "Mikel Arteta";
}
let name = showName() //returns Mikel Arteta
Arrow function
An arrow function is another way to declare a function in JavaScript. Arrow functions allow for the writing of shorter syntax.
const showName = () => {
return "Mikel Arteta";
}
Loops
A loop is a repetition. Loops are used to perform a repeated task based on conditions.
For loops
A for loop is very common in JavaScript. It takes a starting index that’s usually denoted as i followed by the condition. The example below states that because i < 10, we should run the code inside the curly brackets. The third part of the loop is how we increment or decrement the loop. This is denoted as i++.
for (let i = 0; i < 10; i++) {
//do something with each value of i
}
While loop
A while loop performs a task as long as the condition contained in the parenthesis remains true. A while loop is usually preferred when we aren’t sure about the number of times we have to perform a loop. We have to be careful when using a while loop to avoid running into an infinite loop.
let number = 10;
while ( number < 10 ) {
//do something here
//decrement number here to prevent an infinite loop
number--;
}
Arrays and objects
An array is like a bucket list that can hold more than one item. Arrays normally start with the 0 index. This means that the first item in the array is at position 0.
Objects represent key-value pair data stored in a curly bracket.
let names = ["Happy", "Etse", "Savior"]
//array of names
let person = {
name: "Cynthia Bernard",
age: 19,
sex: "female",
occupation: "Nurse",
address: "West Minister Point, London"
}
//person object
A module is dedicated to a quick JavaScript refresher that will keep us informed of what we need to be familiar with when coding ReactJS components for the front-end of our MeteorJS web application. (ReactJS is an open-source JavaScript library used to build user interfaces in a declarative way. )