- An expression is:
- a fragment of code that produces a value,
- every value that is written literally (12 or “mother”),
- an expression between parentheses,
- a binary operator applied to two expressions,
- a unary operator applied to one expression.
Expressions can contain other expressions.
-
A binding or variable is used in JS when a new produced value has to be used, so that the original value remains intact. So we catch and hold values. A special word - keyword(let, var, const) indicates that the sentence is going to define a binding, this is followed by the name of a binding. In order to produce a value these two are followed by an operator and an expression. After a binding has been defined, its name can be used as an expression.
e.g.
let salary = 12 * 800;
let years = 10;
console.log(salaryyears);
96000
to produce the value of the salary earned in 10 years
And this can be changed. A binding points at a value, an operator can be used on existing bindings to disconnect them from their current value and have them point at a new one.
years=12
console.log(salaryyears);
115200
To display the salary earned in 12 years. -
An environment is a collection of bindings and their values that exist at a given time.
A program always contains bindings that provide ways to interact. e.g. in a browser there are functions that interact with the currently loaded website and to read mouse and keyboard input. When we want to access this page from the page of the academy, we do it through the link that has a function written behind that leads us here where we choose to Reply clicking with the mouse and writing in this box. -
A function is a piece of program wrapped in a value. Executing a function is called invoking. Arguments are values given to functions.
-
Examples:
- prompt(“Enter passcode”); - not often used,
- console.log(); to output values - often used.
- A side effect is:
- showing a dialog box (alert, prompt function) or
- writing text to the screen.
-
e.g. function that produces a side effect: alert(“Hello world!”);
e.g. function that produces a value: console.log(2+4); -
Control flow means that the statements in a program are executed from top to the bottom.
-
Conditional execution in JS means we want some code to be exectuted if, and only if, a certain condition holds.
-
if, (together with else to create two alternative execution paths)