-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathside-effects.jsx
More file actions
64 lines (59 loc) · 2.57 KB
/
side-effects.jsx
File metadata and controls
64 lines (59 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from 'react';
export default function SideEffects() {
return (
<div className="space-y-8 font-mono text-sm leading-relaxed">
<div>
<h4 className="text-xs font-bold text-purple-400 uppercase tracking-widest mb-2 border-b border-purple-500/20 pb-1 w-fit">
Medicine
</h4>
<p className="text-gray-400 text-xs">
An unintended secondary effect of a medication or treatment. While
often negative (e.g., drowsiness, nausea), they can sometimes be
beneficial or neutral. In the context of the show, this likely refers
to the unexpected consequences of the "miracle cure."
</p>
</div>
<div className="border-t border-white/10 pt-6">
<h4 className="text-xs font-bold text-blue-400 uppercase tracking-widest mb-4 border-b border-blue-500/20 pb-1 w-fit">
Computer Science
</h4>
<p className="text-gray-400 text-xs mb-4">
A function or expression is said to have a{' '}
<strong className="text-current">side effect</strong> if it modifies
some state outside its local environment or has an observable
interaction with the outside world.
</p>
<div className="bg-black p-4 border border-white/10 my-4 font-mono text-xs overflow-x-auto">
<div className="text-gray-500 mb-2">{'//'} Impure (Side Effect)</div>
<span className="text-purple-400">let</span>{' '}
<span className="text-blue-400">count</span> ={' '}
<span className="text-orange-400">0</span>;
<br />
<span className="text-purple-400">function</span>{' '}
<span className="text-yellow-400">increment</span>() {'{'}
<br />
<span className="text-blue-400">count</span>++;{' '}
<span className="text-gray-500">{'//'} Modifies external state!</span>
<br />
{'}'}
</div>
<ul className="space-y-1 text-gray-500 text-xs pl-4 border-l border-white/10">
<li>-- Modifying a global variable</li>
<li>-- Writing to a file or database</li>
<li>
-- <code>console.log()</code>
</li>
<li>-- DOM manipulation</li>
</ul>
<p className="text-gray-500 text-xs mt-4 italic border-t border-white/5 pt-2">
In{' '}
<strong className="text-current not-italic">
Functional Programming
</strong>
, side effects are avoided to ensure functions are "pure"
(deterministic).
</p>
</div>
</div>
);
}