A Quick Reference Guide to Modern JavaScript Syntax

Code samples often showcase the latest JavaScript features that may sometimes be mistaken for framework-specific features. This is particularly common with frameworks like React, which emphasize a modern approach to JavaScript. This blog post aims to provide clarity regarding these features, especially for those transitioning from pre-ES6 JavaScript or starting from scratch. The goal is to help you identify which constructs are inherent to JavaScript and which ones are specific to a framework....

How to Merge Two Objects in JavaScript

Learn how to merge two JavaScript objects and create a new object that combines their properties. Introduced in ES6 in 2015, the spread operator is a powerful way to merge two simple objects into one: const object1 = { name: 'Flavio' } const object2 = { age: 35 } const object3 = {...object1, ...object2 } If both objects contain a property with the same name, the second object’s property overwrites the first....

JavaScript Function Parameters

Learn the basics of JavaScript Function Parameters. A function in JavaScript can accept one or more parameters. Let’s look at some examples: const doSomething = () => { //do something } const doSomethingElse = (foo) => { //do something } const doSomethingElseAgain = (foo, bar) => { //do something } Starting from ES6/ES2015, functions can have default values for their parameters. Here’s an example: const doSomething = (foo = 1, bar = 'hey') => { //do something } This allows you to call the function without specifying all the parameters:...

The JavaScript Spread Operator: A Comprehensive Guide

In JavaScript, the spread operator ... allows you to expand arrays, objects, and strings. Understanding how to utilize this operator can significantly enhance your coding capabilities. Let’s explore its various applications and examples. Expanding Arrays To create a new array by expanding an existing one, you can use the spread operator. Take the following array a as an example: const a = [1, 2, 3]; Using the spread operator, you can easily create a new array b by appending additional elements:...