Skip to content
Discussion options

You must be logged in to vote

You shouldn’t mutate a variable defined in another cell (without understanding the consequences). If you mutate a variable defined in another cell, then it’s likely that other cells will see the variable in an underdefined state. For example, consider these three cells:

const foo = {};
foo.bar = "bar";
display(foo.bar);

There’s no guarantee that the third cell here will see the value of foo.bar as "bar"; it could be undefined if the third cell happens to run before the second cell. The only guarantee is that the second and third cell run after the first cell (because the first cell defines foo, while the second and third cells reference foo). The evaluation graph looks like this:

What yo…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mbostock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants