JavaScript Basics: Conditionals, Loops and Functions.

Chukwu JoshuaChukwu Joshua
2 min read

In JavaScript, there are certain codes which are considered basic knowledge and will be used all through out your period as a developer. These include: conditional statements, loops and functions.

Conditionals (Conditional Statements)

These are statements that allow for flexibility, in the sense that it allows the developer to define a set of rules and actions that should be carried out if a rule is obeyed or not. it usually starts with an if statement accompanied with an else statement. They usually look like this:

if(condition){
}else{
};

There are other ways to write conditional statements, but they may not allow for definition of more than two rules.

Loops

These allow for repetition without having to write a long code. It has a couple of fun applications, but can turn up interesting bugs should you mess up you code. It can be written as a for statement or do-----while statement, while statements.

for(statement){
//action
};

do{
//action
}while{
//statement
};

Functions

These statement allow the developer define his own set of rules and actions. You can take in variables and values and work with them in the function or you can just define an action to be done. Functions usually have to be called in one way or another, else they remain inactive. You can call them by name or make them automatically loaded at the start of the code. They can be written like this:

function name (variables){
//action
};

There are other ways to write functions one of the most popular types being arrow functions, though you may not be able write complicated functions with them.

Thanks for reading.

0
Subscribe to my newsletter

Read articles from Chukwu Joshua directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chukwu Joshua
Chukwu Joshua