From 2d9d392ad71c1373fd70b66a20ec5823d713b76a Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Sat, 25 Aug 2018 18:39:55 -0400 Subject: [PATCH] Trailing commas --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 6c71f0e..4e5eb46 100644 --- a/README.md +++ b/README.md @@ -482,7 +482,42 @@ console.log( returnOnlyNums(44, false, 'pizza', 45, {season: "winter"}, [1,2,3,4 ## Trailing commas +You can add trailing commas to make copy/paste easier later on: +```javascript +var arr = [ + 1, + 2, + 3, //the comma here will not cause issues +]; + +console.log(arr); +``` + +If you have multiple commas, it will create holes in the array: + +```javascript +var arr = [ + 1, + 2, + 3,,,, +]; + +console.log(arr); +console.log(arr.length); //logs 6 +``` + +Trailing commas are okay in objects too: + +```javascript +var object = { + foo: "bar", + baz: "qwerty", + age: 42, +}; + +console.log(object); +``` ## Template Literals (String Interpolation)