Questions tagged [javascript]

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Use this tag for questions regarding common implementations of ECMAScript, JavaScript, JScript, etc. JS does not typically refer to its ECMA-cousin, ActionScript.

According to the language's creator Brendan Eich, his original inspiration for JavaScript was Scheme. A major requirement handed down to him from management was that the syntax be readily understood by Java developers. Originally called LiveScript, its name was eventually changed to "JavaScript". In all respects, other than sharing part of its name, JavaScript is very different from Java.

It is dynamically typed.

Unlike block-scoped languages the scope chain nests via objects and functions. Local vars declared inside a function will be accessible to the remainder of the function regardless of whether they were defined inside a loop or conditional statement. Nested objects and functions have access to local vars declared in ancestors via a native call object that is not exposed to JS.

It is a functional programming language featuring first class functions which can be passed around as data and applied to new contexts while maintaining links to their original environment execution context through closures. (i.e. a nested function with references to a parent function's local variables will hold on to those values when returned even after the parent function has completed execution)

It is a prototype-based OOP language. New properties can be added to the prototype property of object constructors (simply functions invoked with a 'new' keyword used to create objects with an initiation procedure) and objects that have already been instantiated will still inherit the new properties. Unlike class-based approaches, object constructors in JavaScript do not have the native ability to inherit from one another the way classes can inherit down from a series of super-classes. Such behavior is easily authored however.

Object literals (JSON, basically) are also available.

On the web, where it has seen the most use to date, JavaScript's primary role is to handle data on the client-side, communicate asynchronously with servers (AJAX), assign behavior to events, and allow dynamic manipulation of HTML and CSS through tight integration via the W3C DOM API.

Now with open source availability of JIT compiling engines like Google's V8, JavaScript is starting to spread into new territory though environment implementations like node.js, which allows scripting of JS in the context of file systems and server-side operations.

2111 questions
93
votes
4 answers

Is JavaScript interpreted by design?

I am cautious of asking this question because it might appear overly fastidious. I just opened up JavaScript: The Definitive Guide, and it states of the first page of chapter 1 "JavaScript is a high-level, dynamic, untyped interpreted programming …
Matt Esch
  • 1,183
  • 1
  • 8
  • 10
71
votes
3 answers

How do I make a JavaScript promise return something other than a promise?

I have a spec from a client for an implementation of a method in a module: // getGenres(): // Returns a promise. When it resolves, it returns an array. If given an array of genres, ['comedy', 'drama', 'action'] Here is a skeleton method with a…
sealocal
  • 873
50
votes
1 answer

What is the best way to include JavaScript file using script tag?

I generally include JavaScript files using the script tag as below. I have seen some people using the language attribute as well. Now-a-days I find many people omitting the type attribute.…
Cracker
  • 3,183
48
votes
4 answers

Why is + so bad for concatenation?

Everybody keeps saying that one of JavaScript's problems is using + [example] for string concatenation. Some say the problem is not using +, it's type coercion [see the comments from the previous example]. But strongly-typed languages use + for…
configurator
  • 2,786
39
votes
5 answers

Why aren't there native Javascript interpreters for Windows/Mac/Linux?

It seems to me it would be very useful to use Javascript for general server side scripting tasks as it has more or less the same features as Perl and Python. But AFAIK there are no generally available Javascript interpreters for the major machine…
MebAlone
  • 729
32
votes
14 answers

Is it a common practice to minimize JavaScript usage when building a website?

I've been a web developer for almost 10 years and I've gotten into the habit of trying not to use JavaScript whenever possible. I'm not talking about building web apps here, but database driven websites. Is this a good/respected approach?
Ryan
  • 1,645
28
votes
5 answers

Is rejecting a Promise only for error cases?

Let's say I have this function authenticate that returns a promise. The promise then resolves with the result. False and true are expected outcomes, as I see it, and rejections should only occur in an error case. Or, is a failure in authentication…
26
votes
11 answers

Is javascript worth learning if you do not plan on being a web developer?

I heard Javascript is a full language just like c++. Is this true? What else is it good for programming besides web stuff?
Matt
  • 1,067
25
votes
6 answers

Why do we still use JavaScript?

It seems to me that, despite being one of the world's most used languages, even some of the leading experts of JavaScript like Doug Crockford think JavaScript suffers from some pretty big design flaws (JavaScript: The World's Most Misunderstood…
RoboShop
  • 2,780
  • 6
  • 30
  • 38
23
votes
4 answers

Why coffeescript instead of javascript?

I think somehow building a language which compiles to another language feels like a bad idea from the start, instead of learning javascript properly from the start. Look into Douglas Crockfords Good Parts and then are you hooked. And javascript is…
marko
  • 1,103
21
votes
2 answers

Why does Javascript use JSON.stringify instead of JSON.serialize?

I'm just wondering about "stringify" vs "serialize". To me they're the same thing (though I could be wrong), but in my past experience (mostly with asp.net) I use Serialize() and never use Stringify(). I know I can create a simple alias in…
Chase Florell
  • 651
  • 2
  • 5
  • 16
20
votes
3 answers

Why would I use Angular?

From the basic Angular tutorial, it seems like all it does is fetch some JSON from an API and display it. Also, there's its double binding magic. But why would I use it instead of a backend solution (like Rails) that builds the view in the backend…
gberger
  • 327
19
votes
6 answers

Has anyone used Sproutcore?

Has anyone used Sproutcore for a web application? If so, can you give me a description of your experience? I am currently considering it, but I have a few concerns. First, the documentation is bad/incomplete, and I'm afraid that I'll spend lots of…
Sam Lee
18
votes
6 answers

Self-referencing anonymous closures: is JavaScript incomplete?

Does the fact that anonymous self-referencing function closures are so prevelant in JavaScript suggest that JavaScript is an incomplete specification? We see so much of this: (function () { /* do cool stuff */ })(); and I suppose everything is a…
Tom Auger
  • 847
18
votes
6 answers

Is it better to put the JS code on the html file or in an external file?

If I'm designing a one page website, is it better to create external file for my JS code, or just put it in the html code? Is putting it on the page faster to load? Can I change the permissions to deny the users requests for the code, but the html…
AqeelAT
  • 183
1
2 3
9 10