본문으로 건너뛰기

How to Instruct a Computer

Let's write some code that performs simple calculations and outputs the result values on a computer.

const a = 1;
const b = 2;
const c = 3;

console.log((a + c) * b);

const is a keyword that defines a constant value which does not change during the execution of a program. const a = 1 means that the value 1 is assigned to the constant a.

Here, a keyword refers to a word that has a special meaning already used by JavaScript, which cannot be used as a variable name by the user, and = is an operator that is used to assign values to the constants.


Meaning of =

In programming, the = operator is not used in the sense of "equals" as it is in mathematics; instead, it is used to mean "assign."

Likewise, the constant b is assigned the value of 2, and the constant c is assigned the value of 3.


Meaning of the Multiplication Operator *

In (a + c) * b, the asterisk (*) signifies multiplication. For reference, division operations in programming languages use the slash (/).

Therefore, the value of (a + c) summed and then multiplied by b, which is 4 * 2 = 8, is what gets passed to console.log.


Printing Out

console.log is a function that prints the value passed to it within parentheses (()). Without console.log((a + c) * b), the result of the operation (a + c) * b would not be displayed on the screen.

It's really that simple, isn't it?

This way, you have used JavaScript to instruct the computer to perform simple calculations and print the result.