10

I've been talking with a friend about the purpose of Javascript, when and how it should be used, etc. He quoted that:

JavaScript was designed to add interactivity to HTML pages

[...]

JavaScript gives HTML designers a programming tool

  • HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages JavaScript can react to events
  • A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element JavaScript can read and write HTML elements
  • A JavaScript can read and change the content of an HTML element JavaScript can be used to validate data
  • A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
  • JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser.
  • JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer.

However, it seems like Javascript's getting used to do a lot more than these days. My friend also advocates against using Javascript's OOP functionality, claiming that "you shouldn't be processing data, merely validating." Is Javascript really limited to validating data and making flashy graphics on a web page?

He goes on to claim "you shouldn't be attempting to access databases through javascript" and also says " in general you don't want to be doing your heavy lifting in javascript". I can't say I agree with his opinion, but I'd like to get some more input on this.

So, my question: Has Javascript evolved from the definition above to something more powerful, has the way we use it changed, or am I just plain wrong? While I realize this is a subjective question, I can't find any more information on it, so a few links would be good, if nothing else. I'm not looking for a debate, just an answer.

0

3 Answers 3

21

People who think JavaScript is not a programming language are people who's opinion on JavaScript you should not respect.

JavaScript is a language that has grown organically inspired by semantics of Scheme and syntax of Java. It's original purpose was not general but it has now grown to be so.

JavaScript as a language is suitable to do just about any task if it's fit for it. Take a look at examples like node.js where JavaScript has access to host environment consisting of IO functionality which allows it to be used for generic server side programming

My friend also advocates against using Javascript's OOP functionality, claiming that "you shouldn't be processing data, merely validating." Is Javascript really limited to validating data and making flashy graphics on a web page?

No, JavaScript is a programming language, if you want to represent data structures, algorithms and logic then use the tools the language offers. Specifically 1st class functions and prototypes are powerful tools.

He goes on to claim "you shouldn't be attempting to access databases through javascript" and also says " in general you don't want to be doing your heavy lifting in javascript". I can't say I agree with his opinion, but I'd like to get some more input on this.

Wrong, In the browser we have a database called indexedDB which we access with JavaScript. It's a database baked right into the browser and if you want to use it (and you should) then you use JavaScript.

Also note that both mongodb and couchdb allow you to use javascript to run adhoc queries on the database directly.

As for heavy lifting, he's partly correct. If your doing heavy lifting you should be doing it in C or erlang. Although note that the term "heavy lifting" is vague, for example I wouldn't encode or decode videos in JavaScript, I wouldn't do image processing in JavaScript (use C). I wouldn't no number crunching in JavaScript (use fortran).

Has Javascript evolved from the definition above to something more powerful, has the way we use it changed, or am I just plain wrong

JavaScript was written in a period of 2 weeks just to slap minor scripting functionality into HTML. Since then it has grown severely. Since ES3 (1999) it has been a powerful general purpose programming language.

4
  • "powerful general purpose programming language" that is full of gotchas that will stay there forever because of backwards compatibility: codeproject.com/Articles/182416/…
    – Den
    Commented Aug 15, 2012 at 8:34
  • @Den yeah it has some gotchas, but so does C, C++, PHP and Java.
    – Raynos
    Commented Aug 15, 2012 at 20:47
  • Javascript exceeded this purpose almost from the beginning. You could have had this conversation 15 years ago and the answers would be exactly the same. You could very easily point out to other members of the EMCA script family like ActionScript or languages that seek to emulate the flexibility of JavaScript like Apple's Swift...
    – Raydot
    Commented Feb 25, 2015 at 17:59
  • By the way, let's not forget that Netscape shipped LiveScript (the original name before it was changed to JavaScript as part of a deal with Sun) as a serverside scripting language as part of LiveServer even a couple of weeks before it shipped it as part of Navigator. So, in a sense, JS has been a serverside scripting language even before it became a clientside scripting language. Commented May 27, 2015 at 11:25
10

The vision of your friend is effectively very obsolete, and misses everything which happened since Google released GMail.

Now, does this mean that Javascript developed beyond what it was originally designed to do? Sort of. But don't forget that the design changed meanwhile, and will change in the future according to the new needs from the developers. This is also valid for other popular languages. For example, when the first version of C# was released, no one would expect to allow dynamic code in the design. Now DLR is available for a few years.

2

Language always goes way over what we thought at the begin. Talk to anyone at the beginning of C (or C++), does someone thought that language will be found almost everywhere now. I don't think so.

Each language win to be learn more / push further.

I agree that Javascript was/still a under-appreciate language, your friend isn't the only one. The problem isn't think that the language X or Y is bad/useless, the problem is to keep this idea forever. In Computer Science / IT, everything change quickly, and it will still change a lot in the future.

That's why it's important to keep learn / think outside the box...

1
  • I don't think many people could reasonably say that JavaScript is still an under appreciated language. In fact, I think it's the world's most popular language.
    – Jim G.
    Commented Mar 19, 2012 at 3:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.