JavaScript

JAVASCRIPT JOURNEY (EPISODE 3)

Michael Nii Kwatei Quartey
2 min readJul 26, 2022

Let us move on to objects.

They are more like arrays but instead of indexes, data is accessed through properties. They help store data in a structured manner. Objects also access their properties with the dot (.) and bracket ([]) notation. Objects can be clustered and stored (nested objects). You can modify or add new properties using these notations. To delete a property, we introduce the keyword delete.

Objects allow you to determine the property name using the .hasOwnProperty() which returns true or false if the property is found or not.

While loops run while a condition is met. They stop if otherwise.

For loops come with three expressions separated by a semi-colon (Initialization statement; condition statement; increment/decrement). For loops can also be nested.

Do…While loops have their statements running at least once before a condition is met.

The Math.random() function generates a random decimal number ranging from 0 to 1 (non-inclusive).

We use Math.floor() to round the number down to its nearest whole number.

The function parseInt() parses a string and returns an integer. Once you put in the string literal, it returns an integer after conversion. parseInt() takes a second argument for the radix, which specifies the base of the number in the string. The radix can be an integer between 2 and 36.

E.g. parseInt(“17”, 2) which depicts ’17 base 2'.

NaN refers to “Not a Number”. It represents the result of an invalid operation such as dividing by zero.

The conditional operator can be employed as a one line if-else expression. The syntax is a ? b : c, where a is the condition, b is the code to run when the condition returns true and c is the code to run when the condition returns false.

click here => (next episode)

--

--