MAYA SHAVIN
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
👩💻 Senior Frontend Developer @ Cloudinary
👩🔬 Writer @FrontEndWeekly
👩💼 Portfolio: https://www.mayashavin.com
@MayaShavin
👩💻 Founder of @VueJSIsrael
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
for (let i = 0; i < someArr.length; i++) {
const elem = someArr[i];
//Do something
}
someArr.forEach(element => {
//do something
})
const filtered = someArr.filter(element => {
return matchCondition(element)
));
const filtered = someArr.map(element => {
return { isMap: true, id: element.id }
));
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
let it be constant sweet 🤤
Syntactic sugar - Diabetes alert
respectively
const banana = 'b' + 'a' + + 'a' + 'a';
const banana = `ba${fillme}a`
const hasExpression = expression ? true : false
const hasExpression = !!expression
if (object && object.child && object.child.property) {}
if (object?.child?.property) {}
const myAwesomeArr = new Array();
const myAwesomeArr = [];
Syntactic sugar - Diabetes alert
const result = []
for(let i = 0; i < data.length; i++){
const x = data[i];
if (x % 2=== 0) {
result.push(x)
}
}
const isEven = number => number % 2 === 0
const result = data.filter(isEven)
const myValue = inputValue || 'defaultValue';
let myValue = 'defaultValue'
if (inputValue) {
myValue = inputValue
}
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
const flatternArr = (arr) => arr.reduce(
(flatten, original) => flatten.concat(Array.isArray(original)
? flatternArr(original)
: original),
[]);
const reducer = (flatten, original) => flatten.concat(Array.isArray(original)
? flatternArr(original)
: original);
const flatternArr = (arr) => arr.reduce(reducer, []);
function flatten(arr){
var reducer = (flatten, original) => flatten.concat(Array.isArray(original)
? flatten(original) : original);
return arr.reduce(reducer, []);
}
const emitEvent = (eventId, ...params) => {
((callback) => setTimeout(() => callback(...params)))(events[eventId])
}
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
const mappedData = data
.filter(x => isEven(x))
.map(x => x * 2);
const mappedData = [];
for (let i = 0; i < data.length; i++) {
const x = data[i];
if (isEven(x)) {
mappedData.push(x * 2);
}
}
.reduce(x => x * 2)
// And so on...
Syntactic sugar - Diabetes alert
n = 100000
x 100000
data.filter()
x 100000
filtered.map()
new array created
new array created
x 100000
new array created
modify that array
for(...)
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
const childObj = {
...momObj,
...dadObj
}
const momObj = {
traitA: true,
traitB: false,
uselessInfo: 'uselessInfo',
//...
}
const dadObj = {
traitA: false,
traitB: true,
//...
}
traitA from momObj?
traitB from dadObj?
without uselessInfo?
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
const sumUp = (...numbers) => {
let sum = 0;
for(const number of numbers) {
sum += number;
}
return sum;
}
"use strict";
var sumUp = function sumUp() {
for (var _len = arguments.length,
numbers = Array(_len), _key = 0;
_key < _len; _key++) {
numbers[_key] = arguments[_key];
}
var sum = 0;
for (var _iterator = numbers,
_isArray = Array.isArray(_iterator),
_i = 0,
_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var number = _ref;
sum += number;
}
return sum;
};
>9.x
Syntactic sugar - Diabetes alert
function Point(x, y) {
this.x = x;
this.y = y;
}
var p = new Point(11, 22);
var q = new Point(33, 44);
q.z = 55;
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert
Syntactic sugar - Diabetes alert