These are the topics for week 2:
- Statements vs. Expressions
- Loops
- Control Flow
- Operators
- Conditional statement
- Naming conventions
Your teacher Uday has made video lectures for this week's material. You can find them here: Videos 11 - 20
A lot of programming is nothing different from regular human communication. When conversing with another person, we often use language in various ways: to ask questions, make statements or simply express yourself about what's going on.
This is the same in programming. A difference is that it's done in abstract code. Another difference is that a programming statement is an instruction, while a programming expression leads directly to a value (and are usually different parts of a statement).
To learn more about statements vs. expression, research the following resources:
A loop is a sequence of instructions that is continually repeated until a certain condition is fulfilled. This condition could either be a specified number or when a desired value is found or not.
In programming, a loop is meant to be used in case there's a repetitive task that needs to be done.
Learn more about loops here:
Almost all European languages are read from left to right. In Arabic and Hebrew this is the other way around: from right to left.
In the language of JavaScript this goes from top to bottom, left to right. This is called the control flow
: the order in which the computer executes statements in a script. The control
parts refers to the ability to execute something by the computer, while the flow
part refers to the causal chain between the execution of one action to another.
The term
flow
is a general term meaning a specific, repeatable order of actions. In your working life you'll hear the termworkflow
, which in that case refers to the different actions necessary to complete a business activity.
There is one important distinction between spoken language and programming languages: in programming languages the order in which the code is read can change, depending on various control statements
(if
, for/while/do-while loop
or switch
).
Learn more about control flow here:
If you've ever taken a mathematics class you are familiar with symbols like +
, -
, /
and =
. These symbols are recognized by the computer and are called operators
. They can be used to perform calculations (with numbers) or to determine whether or not something is true (more on that in the next section).
Check the following resources to learn more about their importance:
Computers only function by logical rules: whether something is true or not determines if an instructions gets executed or not. This logical process is expressed in a conditional statement
and goes like this: if this happens, then that happens. Or in code:
if () {
// then this will happen
}
A condition is put in the ( )
and it needs to evaluate to true
or false
(also known as Boolean
values). If the condition is true, then whatever is inside the { }
will be executed.
What happens when the condition is false? For that we have the else { }
block. If the condition is false, then whatever is inside the else will be executed:
if() {
} else {
}
A naming convention is a rule that every developer should hold themselves to when creating variable or function names. This is important, because writing code should be done in a readable way: you should be able to understand what a certain variable or function does just by looking at its name.
Read about the different naming conventions for JavaScript here:
Are you finished with going through the materials? You're doing great! If you feel ready to get practical, click here.