Skip to content

Instantly share code, notes, and snippets.

[JavaScript] - Map

SOURCE

//#region Maps - Fundamental

const map = new Map();
map.set('name', 'Classico Italiano');
map.set(1, 'Firenze, Italy');
map.set(2, 'Lisbon, Portugal');

[JavaScript] - Set

SOURCE

The Set object lets you store unique values of any type, whether primitive values or object references.

const ordersSet = new Set([
  'Pasta',
  'Pizza',
  'Pizza',

[JavaScript] - Looping Objects: Object Keys, Values and Entries

const restaurant = {
  name: 'Classico Italiano',
  location: 'Via Angelo Tavanti 23, Firenze, Italy',
  categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
  starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
  mainMenu: ['Pizza', 'Pasta', 'Risotto'],

[JavaScript] - ES6 Enhanced Object Literal

SOURCE

const weekdays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];

const openingHours = {
  // Object keys can be dynamically assigned in ES6 by placing an expression in square brackets []
  [weekdays[3]]: { 
 open: 12,

[JavaScript] - Looping arrays: the for-of loop

SOURCE

const restaurant = {
  name: 'Classico Italiano',
  location: 'Via Angelo Tavanti 23, Firenze, Italy',
  categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
 starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],

[JavaScript] - Logical Assignment Operators

||=, &&=, ??=

const rest1 = {
  name: 'Capri',
  numGuests: 20,
};

[JavaScript] - Short Circuiting (&& and ||) - Nullish Coalescing Operator (??)

||, &&, Extreme Example

const restaurant = {
  name: 'Classico Italiano',
  location: 'Via Angelo Tavanti 23, Firenze, Italy',
  categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
  starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
 mainMenu: ['Pizza', 'Pasta', 'Risotto'],

[JavaScript] - Spread Operator

SOURCE

const restaurant = {
  name: 'Classico Italiano',
  location: 'Via Angelo Tavanti 23, Firenze, Italy',
  categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
  starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
 mainMenu: ['Pizza', 'Pasta', 'Risotto'],

VS Code - Java Script region

SOURCE

//#region
code
//#endregion

[JavaScript] - Destructuring Objects

SOURCE

const restaurant = {
  name: 'Classico Italiano',
  location: 'Via Angelo Tavanti 23, Firenze, Italy',
  categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
  starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
 mainMenu: ['Pizza', 'Pasta', 'Risotto'],