This article is sponsored by Hostgator - Get Started today for $0.99
Statements
Statements generally are instructions to be executed by a computer program.
A JavaScript program or code is a list of programming statements
Statements in computer programming are executed from top to bottom (and left to right) in the order they appear.
console.log('Hello World!')
When there is more than one statement in a JavaScript program, it is recommended to end statements with a semi-colon.
console.log('Good Day!');
console.log('Happy Codding!');
Although without ending each statement with a semi-colon, computer programs will most likely execute successfully.
console.log('Good Day!')
console.log('Happy Codding!')
There are a few cases when ending statements without semi-colon can lead to errors.
It is also a good practice to end statements with semi-colon because it makes the code more readable and understandable.
console.log('Good Day!');
const func = num => {
console.log(num);
};
[1, 2].forEach(func);
In the example above, ending statements with a semi-colon makes your code readable because it marks the end of a statement.
White Space
Apart from ending each statement with a semi-colon for better readability, we can do more justice to make a program more readable.
console.log('Good Day!');
const func = num => {
console.log(num);
};
[1, 2].forEach(func);
It would be better to separate each separate set of independent instructions with a new line or white space.
console.log('Good Day!'); // independent of the code below
const func = num => {
console.log(num);
};
[1, 2].forEach(func);
Since words are usually separated by white space when writing a letter, an article, etc. In programming also, there's no exception to this rule.
let firstName = 'Osagie';
let lastName = 'Bello';
console.log('My name is ' + firstName + ' ' + lastName);
Statements are composed of values (
Osagie
andBello
), Operators (+
and=
), keywords (let
), and expressions (statements with=
in-between keyword and value)
A statement can also be an expression without an equal sign assignment operator =
only if it can be evaluated.
5 * 4; // an expression
Variables
Initialization of a variable to a value is done by an equal sign (=
) in-between them.
let myName = 'Bello';
The value (data) Bello
is assigned to a variable name, myName
in the example above. In computer programming, the equal sign which separates the value and variable is called an assignment operator.
camelCase
camelCase is a naming convention of variable, function, and class names when it contains more than one word.
let myName = 'Bello';
myName
are two words in a variable, my and name.
Happy Coding!!!
Techstack | Hostgator
Techstack article is sponsored by Hostgator.
- A ton of website hosting options
- 99.9% uptime guarantee
- Free SSL certificate
- Easy WordPress installs
- A free domain for a year
Discussion (0)