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.

2101 questions
545
votes
6 answers

Pros and Cons of Facebook's React vs. Web Components (Polymer)

What are the main benefits of Facebook's React over the upcoming Web Components spec and vice versa (or perhaps a more apples-to-apples comparison would be to Google's Polymer library)? According to this JSConf EU talk and the React homepage, the…
CletusW
  • 5,453
  • 3
  • 14
  • 6
302
votes
5 answers

Is there any reason to use the "var" keyword in ES6?

Babel's guide to ES6 says: let is the new var. Apparently the only difference is that var gets scoped to the current function, while let gets scoped to the current block. There are some good examples in this answer. I can't see any reason to use…
callum
  • 10,377
  • 9
  • 30
  • 33
291
votes
7 answers

Does using == in JavaScript ever make sense?

In JavaScript, the Good Parts, Douglas Crockford wrote: JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=. The good ones work the way you would expect. If the two operands are of the same type and have the…
Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
227
votes
6 answers

How much should I be using 'let' vs 'const' in ES6?

I've been writing a lot of ES6 code for io.js recently. There isn't much code in the wild to learn from, so I feel like I'm defining my own conventions as I go. My question is about when to use const vs let. I've been applying this rule: If…
callum
  • 10,377
  • 9
  • 30
  • 33
208
votes
1 answer

Why are native ES6 promises slower and more memory-intensive than bluebird?

In this benchmark, the suite takes 4 times longer to complete with ES6 promises compared to Bluebird promises, and uses 3.6 times as much memory. How can a JavaScript library be so much faster and lighter than v8's native implementation written in…
callum
  • 10,377
  • 9
  • 30
  • 33
172
votes
4 answers

Why is JavaScript not compiled to bytecode before sending over the network?

You'd often see that JavaScript is actually being transported over the web with all the useless stuff that doesn't need to be there -- Comments, particularly those containing licenses, indentations ('\t', '\n'), etc. Given enough time, it could end…
zombiesauce
  • 1,429
  • 2
  • 6
  • 8
169
votes
3 answers

Benefits of Structured Logging vs basic logging

We're building a new app and I'd like to include structured logging. My ideal setup would be something like Serilog for our C# code, and Bunyan for our JS. These would feed into fluentd and then could go out to any number of things, I was thinking…
DTI-Matt
  • 1,799
  • 2
  • 10
  • 5
160
votes
8 answers

Developing web applications for long lifespan (20+ years)

I'm currently developing a web application for government land planning. The application runs mostly in the browser, using ajax to load and save data. I will do the initial development, and then graduate (it's a student job). After this, the rest of…
Dan
  • 1,508
  • 2
  • 10
  • 12
147
votes
15 answers

Why did memory-managed languages like Java, Javascript, and C# retain the `new` keyword?

The new keyword in languages like Java, Javascript, and C# creates a new instance of a class. This syntax seems to have been inherited from C++, where new is used specifically to allocate a new instance of a class on the heap, and return a pointer…
Channel72
  • 2,475
  • 5
  • 27
  • 28
117
votes
13 answers

Why the recent shift to removing/omitting semicolons from Javascript?

It seems to be fashionable recently to omit semicolons from Javascript. There was a blog post a few years ago emphasising that in Javascript, semicolons are optional and the gist of the post seemed to be that you shouldn't bother with them because…
Jonathan
  • 1,839
  • 2
  • 12
  • 11
111
votes
20 answers

Should I bother to develop for JavaScript disabled?

Should I bother to develop for JavaScript disabled? I feel that my time is better spent developing for the majority.
Jiew Meng
  • 2,261
  • 3
  • 20
  • 26
110
votes
3 answers

Why do Trampolines work?

I've been doing some functional JavaScript. I had thought that Tail-Call Optimization had been implemented, but as it turns out I was wrong. Thus, I've had to teach myself Trampolining. After a bit of reading here and elsewhere, I was able to get…
Ucenna
  • 1,292
  • 2
  • 10
  • 19
108
votes
6 answers

Does immutability hurt performance in JavaScript?

There seems to be a recent trend in JavaScript towards treating data structures as immutable. For example, if you need to change a single property of an object, better to just create a whole new object with the new property, and just copy over all…
callum
  • 10,377
  • 9
  • 30
  • 33
99
votes
2 answers

What is JavaScript, really?

All this started when I was looking for a way to test my webpage for JavaScript conformance like the W3C HTML Validator. I have not found one yet. So let me know if you know of any... I looked for the official JavaScript page and find ECMA Script.…
Lord Loh.
  • 1,767
  • 1
  • 14
  • 22
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
1
2 3
99 100