tags:

views:

298

answers:

4

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

As per my knowledge its called so because javascript is only interpreted by the browser (and not compiled). Correct me if I am wrong.

Also if there is no compilation then how come 0 == '' is true? Doesn't the compiler coerce the values (is it related to javascript engine)? I am a bit confused.

+9  A: 

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 coersion it is not necessarily achieved by a compiler; it's all about the Java script 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.

victor hugo
Thanks victor for helping me..but any info abt my 2nd qs?
Wondering
I missed that one. Done...
victor hugo
yeah, I got ur point.
Wondering
In Javascript == tries to covert the type of RHS to the left hand side if they are not equal. For this reason '' == 0 is false but 0 == '' is true. Same goes false == '0' being true. It is better to use === and !==
Tanmoy
+3  A: 

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.

musicfreak
for clarity - a scripting language can be for the OS rather than an 'application' (enter argument about whether shells constitute applications) :)
Luke Schafer
Thanks for ur inputs.I got it now.
Wondering
A: 

it's an interpreted language that is sandboxed in its access and utilized for a particular purpose.

This means:

  • it is interpreted when run, it is not compiled
  • It is given limited access to the system, usually though a specific API
  • It is usually only given API calls that help it achieve its intended purpose and nothing more (though third-party additions can be used)
Luke Schafer
A: 

The idea of a scripting language is one that instructs a host to carry out a series of actions (a lot like an actor reading from a script).

Javascript tells a browser what to do and how to process things just the same way that a shell script, php, or any other scripting language does for their respective hosts.

Gabriel Hurley