From 2e92a63a690fc35f82ad14cea9daae428a55cf90 Mon Sep 17 00:00:00 2001 From: Ha Anh Nguyen Date: Thu, 1 Nov 2018 11:02:04 +0200 Subject: [PATCH] Add example to concisely return object (#20707) * Add example to concisely return object This trick to directly and concisely return object might be useful for beginners * Change function name and logic Change function name and logic to make sense --- guide/english/javascript/arrow-functions/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guide/english/javascript/arrow-functions/index.md b/guide/english/javascript/arrow-functions/index.md index a8ce0a8eac..d8be25e6ca 100644 --- a/guide/english/javascript/arrow-functions/index.md +++ b/guide/english/javascript/arrow-functions/index.md @@ -40,6 +40,9 @@ const multiply = (x, y) => x * y; // if you only have one argument/parameter const multiplyBy2 = x => x * 2; +// if you need to concisely return an object, you can wrap the {} inside the () to avoid syntax conflicts +const getSumProductObject = (x, y) => ({sum : x + y, product: x * y}); + // combined with the ternary operator, but note it's not a looker! const addOrMultiply = (x, y, mathOperator) => mathOperator.toLowerCase() === 'add' ? x + y : x * y; ```