NOTE: Adding ‘;’ at the end of statements is optional, but you MAY have issues later if you don’t! Learn more about it here
VARIABLES
Variables are declared with ‘var’ or ‘let’. These variables can be changed.
On the other hand, constants are declared with ‘const’ and they can be changed after being defined.
NOTE: It’s recommended to use let instead of var. For more info, look up “JS Variable Scopes”
CONDITIONALS
Conditional statements check whether a specified condition is true or false. It determines what event happens next. It involves an if statement. Else if and else statements are optional.
LOOPS
Loops allow you to execute lines of code repeatedly until a specified condition is reached. Below is a for loop. There are multiple types of loops in Javascript:
for, while, do-while, for-in, and for-of.
QUESTION: numbers[2] = ?
FUNCTIONS
Rather than coding the same lines out multiple times in different situations, create a function and simply call it when needed.
Adding comments will allow yourself and others to further understand the code. Some IDEs may even provide a preview (see above).
When countOddEven() is called, it executes the instructions in the defined code block.
THANK YOU
Follow @codeherk for tips on Software Development
QUESTIONS
Do you still use var in JavaScript?
Do you add comments, before, during, or after coding?