Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is JavaScript called a "scripting language"?

As the title says, I want to know the exact reason why JavaScript is called a "scripting language"?

My understanding is it's because JavaScript is only interpreted by the browser (and not compiled). Correct me if I'm wrong.

But if there is no compilation then how come 0 == '' is true? Doesn't the compiler coerce the values, or is that the JavaScript engine...? I am a bit confused.

like image 572
Wondering Avatar asked Jun 09 '09 06:06

Wondering


People also ask

Is JavaScript programming or scripting?

JavaScript is a lightweight interpreted programming language. The web browser receives the JavaScript code in its original text form and runs the script from that.

Why JavaScript is the best scripting language?

JavaScript is the most popular language above Java, Python, Ruby, and more. JavaScript is the language that browsers use. It's easy to get started with and to understand. You can get going right away - unlike other languages, you don't have install a bunch of programs before you can even begin.


2 Answers

I think first two sentences from wikipedia are clear enough:

A scripting language, script language or extension language is a programming language that allows some control of a single or many software application(s). Languages chosen for scripting purposes are often much higher-level than the language used by the host application...

In this case, the application is the browser. And about compilation:

Scripts are often, but not always, interpreted from the source code or "semi-compiled" to bytecode which is interpreted, unlike the applications they are associated with, which are traditionally compiled to native machine code for the system on which they run

About 0 being equal to '', the coercion it is not necessarily achieved by a compiler; it's all about the JavaScript engine in runtime.

I feel sorry for taking everything from Wikipedia but it's so clear and I put it quoted

PS: I find worth to paste this too:

Many people view 'scripting' languages as inferior or somehow different than languages that haven't achieved popularity on the scripting scene. Ironically, these same languages were carefully chosen for scripting due to their quality and versatility.

like image 95
victor hugo Avatar answered Sep 21 '22 06:09

victor hugo


You're partially right. A scripting language is basically a language that doesn't stand by itself; it "scripts" another application (in this case, the browser). I think what you're thinking of is an interpreted language. What that essentially means is that it isn't compiled (at least not in the traditional sense), it's "interpreted" from the source code. Your example actually has nothing to do with compilation. The type conversion from a string to an integer is done at runtime.

like image 33
Sasha Chedygov Avatar answered Sep 21 '22 06:09

Sasha Chedygov