r/learnjavascript • • Jan 11 '24

Is JavaScript just a C language behind the scenes?

I've come to realization that node js is nothing but complicated C program, that would mean that Javascript is an implementation right?. I've read that JavaScript was created in the late 90s so did they create it with a language like C?

0 Upvotes

21 comments sorted by

11

u/FreezeShock Jan 11 '24

The JS engine that runs your JS would be written in some other language like C. Technically you could write it in basically any language.

2

u/DrShocker Jan 11 '24

And Bun for example is written in Zig

5

u/JazzApple_ Jan 11 '24

I believe the term you’re looking for is “interpreted”. JavaScript is an interpreted language and the “interpreter” is written in a different language like C++.

You can see this in the fact that, to run JS you typically run another program like node which has been compiled to machine code.

5

u/[deleted] Jan 11 '24 edited Jan 11 '24

Node.js is mosty written in C++. So basically it's like Roblox, where you have Lua for scripting and the underlaying engine that does all the heavy work.

But by your logic you could say, that I write rust as that is the language deno is using. And bun is written in zig...

Can't wait for Java written runtime 😆 (that would actually be hilarious)

6

u/mcaruso Jan 11 '24

Rhino is a JS engine in Java. I guess it's more analogous to V8 than Node/Deno/Bun, but there you go.

2

u/[deleted] Jan 11 '24

Thank you! So you have bytecode language inside of a runtime written in bytecode language

2

u/zarlo5899 Jan 11 '24

yes but the jit makes it okay

2

u/daydream49133 Jan 11 '24

As far as I know, C used to be just a program written in assembly (not anymore though). Every language starts as a program written in another language

2

u/zarlo5899 Jan 11 '24

yep the bootstrap

make a minimal compiler in another language to compile the compiler for your new language

1

u/pedersenk Jan 11 '24

C is compiled to assembly then (or directly) to machine code. It executes directly on the processor. No "program" required to do this unlike i.e the Javascript VM

That said, things like Emscripten, C++/clr, Adobe Crossbridge compile C and C++ to Javascript/Wasm, .NET bytecode, Flash bytecode respectively in which case it becomes a little closer to how Javascript is JIT/interpreted.

Interestingly, most assemblers are also written in C these days, so things start to loop back at this level.

2

u/DeviantPlayeer Jan 11 '24

In that sense everything is a machine code behind the scene.

4

u/Samurai___ Jan 11 '24

All I see is zeros and ones.

3

u/azhder Jan 11 '24

But those are abstractions.

There is only a presence or absence of electric signals and/or magnetized surfaces and/or charged condensers.

3

u/[deleted] Jan 11 '24

[removed] — view removed comment

3

u/azhder Jan 11 '24

But there aren’t particles, they are just quanta of fields that may be viewed as waves or particles, but aren’t either or are both at the same time (take your pick).

2

u/[deleted] Jan 11 '24

Node is C++, C++ is assembly, Assembly is binary

All programming languages end up as binary if you dig deep enough

2

u/azhder Jan 11 '24

You can view almost every program as a C/C++ behind the scenes, especially C since it was the “OS language” ever since inception.

C was made to be so close to assembly and hardware that, considering the amount of low level and OS software, almost everything is built on top of it.

This means, it may help you to understand C, but it is not necessary to know it in order to use software (appearing to be) written in C

2

u/shgysk8zer0 Jan 11 '24

I'm pretty sure Firefox/SpiderMonkey is Rust.

2

u/azhder Jan 11 '24

As far as I remember, SpiderMonkey was in C++ and if/when they switched to Rust, they named the engine something else. Just don't take my word for it, I haven't followed up on the changes so much.

1

u/binocular_gems Jan 11 '24

Most people answered the question in that yes, Node is an application written in C++, a superset of C, and C is written in Assembly, and Assembly is written in binary, and so NodeJS is compiled back to a binary.

But, one thing to add, JavaScript is not an implementation of Node. Node is a runtime for executing JavaScript, in a similar way that your browser has a runtime for executing JavaScript (for Chromium this is "V8", Safari it's JavaScriptCore, Firefox is SpiderMonkey).

JavaScript/LiveScript/Mocha/ECMAScript was originally written in C as a component of Netscape, which was originally Mosaic, written in C, for X Window GUI for Linux.