Isn't JS the stupidest language?

D

Darko

Isn't JS the stupidest language?

<script>
function x()
{
var i = 2;
alert( "i = " + i );
if ( i == 2 ) {
var i = 3;
alert( "i = " + i );
}
alert( "i = " + i );
}

x();

</script>


What would you expect to see?
 
M

Martin Honnen

Matt said:
Javascript doesn't have block scope.

JavaScript 1.7 has:

<script type="text/javascript; version=1.7">
function x()
{
let i = 2;
alert( "i = " + i );
if ( i == 2 ) {
let i = 3;
alert( "i = " + i );
}
alert( "i = " + i );
}

x();
</script>
 
D

Douglas Crockford

Darko said:
Isn't JS the stupidest language?

<script>
function x()
{
var i = 2;
alert( "i = " + i );
if ( i == 2 ) {
var i = 3;
alert( "i = " + i );
}
alert( "i = " + i );
}

x();

</script>


What would you expect to see?

JavaScript certainly has more than its share of stupid features. In this case,
presenting a syntax that promises block scope but not delivering block scope
will induce programmers to make mistakes as you demonstrated, and you could well
argue that a language that encourages mistake making is stupid.

But there are other features of JavaScript that are very smart. And most of the
stupidities can be avoided by using JSLint. The combination of JavaScript and
JSLint make a very smart language.

http://www.JSLint.com/
 
L

-Lost

Douglas said:
JavaScript certainly has more than its share of stupid features. In this
case, presenting a syntax that promises block scope but not delivering
block scope will induce programmers to make mistakes as you
demonstrated, and you could well argue that a language that encourages
mistake making is stupid.

But there are other features of JavaScript that are very smart. And most
of the stupidities can be avoided by using JSLint. The combination of
JavaScript and JSLint make a very smart language.

http://www.JSLint.com/

I've always enjoyed the fact that JSLint results in 4 errors on JSLint's
code. All of which are "eval" related.

Although I believe JSLint picks up on its own "eval is evil" message for
2 of those errors. (Perhaps the rest.)
 
D

Douglas Crockford

-Lost said:
I've always enjoyed the fact that JSLint results in 4 errors on JSLint's
code. All of which are "eval" related.

Although I believe JSLint picks up on its own "eval is evil" message for
2 of those errors. (Perhaps the rest.)

You seem to always enjoy being wrong.
 
L

-Lost

Douglas said:
You seem to always enjoy being wrong.

Would you mind telling me how I am always wrong? I would seriously like
to know so I can learn the correct information to whatever you say I am
always wrong on.

Anyway...

I wasn't attempting to disrespect you by any means. I just found it
slightly humorous that JSLint errors 4 times about "eval."

Run http://www.jslint.com/webjslint.js through your JSLint and you get:

Error:
Problem at line 86 character 37: eval is evil.
Problem at line 182 character 720: eval is evil.
Problem at line 199 character 34: eval is evil.
Problem at line 283 character 119: eval is evil.

And I specifically noticed that 2 of those had warning("eval is evil"),
which was obviously not you using "eval," it was just the presence of
"eval" in that string.

Is that not right? Those messages are output from your code. What was
I wrong about?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top