Not asking about the implementation of JavaScript.
Just a heads up, if you are planning to create a dark mode for your application, you no longer need to use JavaScript, you can simply do it by @media query.
For example
@media (prefers-color-scheme: dark) {
.day.dark-scheme { background: #333; color: white; }
.night.dark-scheme { background: black; color: #ddd; }
}
@media (prefers-color-scheme: light) {
.day.light-scheme { background: white; color: #555; }
.night.light-scheme { background: #eee; color: black; }
}
I am want to know...

Obviously, I am not a designer. So here is my programmer's easy way to get a dark-mode. I already used this method for some apps and websites before, and I (and my clients, if there were any) was always rather pleased. I am sure there are better ways out there and I am also pretty sure that designers will tell you that what I do is a bad idea.
I usually start with the light mode when creating an app. It's standard and in most cases, people are more comfortable with it. However, remember, I am not a designer. I don't care about 100% color accuracy - which is not possible on computer screens anyway. I don't care about fancy color math. That's why I prefer to use HSL colors - which is a different color space from what a computer can actually display, hence there are math errors when displaying the final color. However, HSL is a lot easier to use, because I select a hue, then set the saturation and the lightness. For a light color scheme, the lightness is usually rather high for your main colors and low for contrast colors.
Then, when it's time to create a dark theme, what I do is I try a few things. First I inverse the lightness of the colors, so I get a dark site with bright contrasts. For example, if your colors are
hsl(0, 0%, 99%)for a white background,hsl(218, 99%, 65%)as your primary color andhsl(0, 0%, 3%)as your contrast / text color, then you'd switch them tohsl(0, 0%, 1%),hsl(218, 99%, 35%)andhsl(0, 0%, 97%).This does not always work perfect, so from there, I start to shift the light factor around until my eyes don't hurt from bright elements anymore. Then, I change the saturation. Often, the saturation is too fruity for a dark theme when coming from a light theme imho. So I turn it down a bit. The result is a dark theme, using the exact same hue as the light theme, but nice and dark.
The advantage: You can keep your hue palette, which means that users will recognize the colors and the site still gives off a familiar feeling. Here's an example: