Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
798 views
in Technique[技术] by (71.8m points)

firefox - What browsers currently support JavaScript's 'let' keyword?

I'm developing an app and don't have to ever worry about Internet Explorer and was looking into some of the features present in A+ grade browsers that aren't in Internet Explorer1.

One of these features I wanted to play around with is JavaScript's let keyword

I can't seem to get any of their 'let' examples to work in Firefox 3.6 (User-Agent string: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)). I get SyntaxError: missing ; before statement when executing let foo = "bar".

So, what browsers support the let keyword? (Or am I doing something wrong?)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

EDIT: let and const are supported by all modern browsers and are part of the ECMAScript 2015 (ES6) specification.

Basically if you don't need to support anything below IE11, let and const are safe to use nowadays.

On IE11 there's a small quirk with let when used with for loops, the variable is not bound to the for block as you would expect, it behaves as var did...

See also: let and const support.


Old and outdated answer from 2010: Those extensions are not ECMA-Standard, they are supported only by the Mozilla implementation.

On browser environments you should include the JavaScript version number in your script tag to use it:

<script type="application/javascript;version=1.7">  
  var x = 5;
  var y = 0;

  let (x = x+10, y = 12) {
    alert(x+y + "
");
  }

  alert((x + y) + "
");
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...