This is how you instruct the machine! 🤯

·

2 min read

JSwL: Episode 3

The machine can only perform actions or operations when given a statement. Before we dive into statements, you should know these three concepts:

  • A program is a set of instructions that tells the machine what to do.

  • The valid format for writing instructions in a particular language is known as syntax.

  • An expression is any reference to a variable or value, or a set of variables and values combined with operators.

Now let's learn about statements..

Here are 3 quotes

“Statements are syntax constructs and commands that perform actions.

We can have as many statements in our code as we want. Statements can be separated with a semicolon usually written on separate lines.

A semicolon may be omitted in most cases when a line break exists. JS interprets the line break as an “implicit” semicolon.“ - JS info

“JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon.” - MDN docs

“In a computer language, a group of words, numbers, and operators that performs a specific task is a statement.

Programs are just collections of many such statements, which together describe all the steps that it takes to perform your program’s purpose.

Statements are made up of one or more expressions.” - Kyle Simpson

2 code samples

// sample 1
var a = 2

// sample 2
alert("Hello");

[1, 2].forEach(alert);
// output = Hello, 1, 2

1 exercise

Try giving an explanation while solving this.

alert("Hello")

[1, 2].forEach(alert); // output?

That's a wrap! see you on the next one.

Connect with me on Twitter.

Â