Script Editor app is for AppleScript. TextEdit is a plain text or rich text editor. You need a real programming or code editor like Atom, BBEdit, Textastic, SublimeText, TextMate, VSCode, or a million and one other choices, many free.
Edit in TextEdit – but make sure the document is set to plain text (Format>Make Plain Text), not rich text, or TextEdit may do all kinds of screwy things that can break code, like changing straight quotes to “smart” quotes.
Then after saving, e.g. as script.js.txt, go to the file in the Finder and change the filename so the extension is just .js
Longer term, do as @karlnyhus suggests and get to know a code-oriented editor.
If you have need to edit code, I might suggest the free mode version of BBEdit. If you download BBEdit, you will get the full version for 30 days. After that, if you choose to pay for it, you get the full version to continue using. Otherwise, it reverts to the free version, which you would find more than sufficient for list code editing duties.
As a long-time BBEdit user, I continue to highly recommend it. It is always open on my computer, and I use it for virtually all text editing tasks. I also write all of my shell scripts and python code in it. (I do use Xcode for larger projects and for Swift due to its built in help and code completion, but that’s more than you need here.)
The other options suggested will also work, eg using TextEdit and saving as .txt and then removing that extension, but you do have to be careful with line endings and you won’t get the syntax highlighting that BBEdit can provide, among other things.
SublimeText is an awesome editor, but I haven’t gone to it primarily because I am so used to BBEdit at this point.
As it is a once off and my attempts to edit javascript are rarer than hen’s teeth, I took the suggested path of simply changing the extension on the desktop and that seems to have worked.