React Hooks

React Hooks are function calls that allow us to include state in a functional component. State is kept isolated from components to keep the component stateless and pure, and the state reuseable. Hooks allow us to reintroduce statefull logic into components whilst preserving these features.

Prevent the page reloading on a form submission

The prevent the page reloading when you submit a form, call the preventDefault() method on the submit event. A form by default will send a request to a given location. Unless the action attribute is specifed, the form will send a request to the current location. The form will send the request when the submit … Read more

Modulo oblongata

The modulo (or modulus) operator % returns the remainder of a division operation. 3 % 0 === NaN (cannot divide by 0)3 % 1 === 0 (3 remainder 0)3 % 2 === 1 (1 remainder 1)3 % 3 === 0 (1 remainder 0)3 % 4 === 3 (0 remainder 3) A classic use case for … Read more

Declaring a function

To declare a function in JavaScript, use the function keyword, a function expression, or an arrow function. To use the function keyword to declare a function, simply precede the function name with the word function, then append the function name with a set of parentheses followed by a set of braces. To use a function … Read more

Reversing an array

To reverse the order of elements in an array in JavaScript, use the reverse() method. The reverse() method will swap the order of elements in an array such that the first will become the last and so forth. The reverse() method is an example of an in-place operation which means the original array is transformed … Read more

The ternary operator

The ternary operator evaluates a condition then returns one of two responses depending on whether the condition evaluates as true or false. The structure of the ternary operator is as follows: condition ? response if true : response if false The ternary operator can be used to assign a value to a variable depending on … Read more

Get the data type of a variable in JavaScript

To get the data type of a variable in JavaScript, use the typeof keyword before the variable name. The typeof keyword returns the data type of the variable or property that follows it. In JavaScript, an array is an object type, therefore the keyword typeof will return object for both arrays and traditional objects. A … Read more

Commenting your code

Comments provide useful context to your code so you and other developers can better understand the purpose of that code upon review. Comments can be used to provide information about a line of code, such as the intended function and possible inputs and outputs. Comments can also be used to hide code from being executed … Read more