Published
Edited
Aug 9, 2019
Insert cell
md`# Javascript mutability experiment`
Insert cell
fn = function(x) {
// I think, instead, we can be aware of this behvaior.
let y = x;
y.a = 3;
return y;
}
Insert cell
x = ({b: 2})
Insert cell
y = fn(x)
Insert cell
x
Insert cell
fnNew = function(x) {
// I'm not convinced we need to do this.
let y = JSON.parse(JSON.stringify(x));
y.a = 3;
return y;
}
Insert cell
xNew = ({b: 2})
Insert cell
yNew = fnNew(xNew)
Insert cell
xNew
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