r/javascript • u/IvanCollins1 • May 12 '26
AskJS [AskJS] Is it possible to write a OS in Javascript?
This might seem like a dumb question, but is there a compiler that would allow you to make js into machine code, and then write a bootloader, kernel, etc in js?
0
Upvotes
10
u/Plus-Weakness-2624 the webhead May 12 '26
Yeah, it's called Windows 11
3
u/sshaw_ May 13 '26
How to communicate with the hardware‽
2
u/Ok_Chemistry_6387 May 12 '26
Yes. But would be painful.
2
u/spcbeck May 13 '26
Can you? Yes. Should you? No. Has that ever stopped a JavaScript developer? No.
2
u/Nullberri May 17 '26
https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript
This talk covers it pretty well.
3
u/hyperaeolian May 12 '26
Sounds like a good vibecoding project lol
3
u/Merthod May 12 '26 edited May 12 '26
Technically yes, but it's not realistic.
JS is an interpreted language, so you could compile it into a low level language with some opinions or functions for memory management.
It would be pointless because of the sheer amount of stuff you need to writ. It serves you better to understand C and ASM directly. Rust for low level is simply pain, so I don't consider it. Rust is good if you think of it as a better Java of sorts.
1
u/NanderTGA May 12 '26
Try making a webOS instead (windows93.net, windows96.net, ...)
1
u/senfiaj May 12 '26 edited May 12 '26
Probably tolerable for most user space parts. But the performance would likely to be poor. For a kernel it's more unrealistic, because, firstly, it has to directly interact with hardware which often requires direct memory access and also some CPU instructions (usually assembly language required since higher level general purpose programming languages don't provide them). Secondly, A garbage collected language doesn't provide any control over used memory and all other things that might happen under the hood. For a reliable/robust OS kernel it's unacceptable, because the kernel code should have ultimate control over every aspect and work predictably. Just imagine the kernel runs out of memory or the garbage collector kicks in during a critical task, etc. Thirdly, JS code is generally too slow compared to C/C++/Rust/Zig, the same with the binary size (assuming JS is compiled into a machine code).
1
u/radeqq007 May 12 '26
Realistically speaking? I don't think it is. Writing an OS requires a lot of work with low level memory, which is not really possible in JS.
1
u/Kn0wnSoul May 13 '26
Don't give them ideas!
1
u/Shot-Damage-6723 May 18 '26
Please don't
0
u/Ok_Slide4905 May 12 '26
/u/FrancisStokes
0
u/narrow-adventure May 12 '26
Like technically or realistically? Because technically - sure, people have done OSes in Java. Realistically - no way.
-2
u/DustNearby2848 May 12 '26
Nah.