Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long can variable and function names actually be in Javascript? [duplicate]

Possible Duplicate:
Maximum length of variable name in JavaScript

While reading on a bit of JS, I thought to myself: how long can my names be?

    function myNormalFuncName () {//...}
    var myNormalVarName = 'how long?';

So my question is how long can it be? Is there any kind of mechanism that stops this from happening, or is there any kind of error thrown? Or maybe even a overflow or something like that? Or will it just work fine?

Maybe it depends more on the implementation? So how about modern browsers.

Would love to hear what skilled developers know about this.

like image 361
jeroen Avatar asked Aug 12 '26 23:08

jeroen


1 Answers

Fine for at least 999999 characters

var code = 'var ' + Array(1000000).join("a") + ' = 1;';
eval(code);
alert( window[Array(1000000).join("a")] ); //1
like image 98
Esailija Avatar answered Aug 14 '26 14:08

Esailija



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!