Published
Edited
Apr 28, 2019
5 stars
Insert cell
Insert cell
{
return [...new Set([1, 2, 3, 3])]
}
Insert cell
Insert cell
{
return [1, 0, null, 2, false, '', 3, NaN].filter(Boolean)
}
Insert cell
Insert cell
{
let dict = Object.create(null);
return dict.__proto__;
}
Insert cell
Insert cell
{
const person = { name: 'David Walsh', gender: 'Male' };
const tools = { computer: 'Mac', editor: 'Atom' };
const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' };

return {...person, ...tools, ...attributes};
}
Insert cell
Insert cell
{
const isRequired = () => { throw new Error('param is required'); };

const hello = (name = isRequired()) => { console.log(`hello ${name}`) };

// This will throw an error because no name is provided
//hello();

// This will also throw an error
//hello(undefined);

// These are good!
hello(null);
hello('David');
}
Insert cell
Insert cell
{
const obj = { x: 1 };

// Grabs obj.x as { x }
const { x } = obj;

// Grabs obj.x as as { otherName }
const { x: otherName } = obj;
return otherName;
}
Insert cell
Insert cell
{
var urlParams = new URLSearchParams('?post=1234&action=edit');

console.log(urlParams.has('post')); // true
console.log(urlParams.get('action')); // "edit"
console.log(urlParams.getAll('action')); // ["edit"]
console.log(urlParams.toString()); // "?post=1234&action=edit"
console.log(urlParams.append('active', '1')); // "?post=1234&action=edit&active=1"
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more