Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length of variable name in JavaScript

What is the maximum length of a variable name in JavaScript?

like image 201
Allan Bowe Avatar asked Nov 27 '09 14:11

Allan Bowe


People also ask

What is the maximum length of a variable name?

Variable names can be upto 32 digits.

What is max length of string JavaScript?

ECMAScript 2016 (ed. 7) established a maximum length of 253 - 1 elements. Previously, no maximum length was specified. In Firefox, strings have a maximum length of 230 - 2 (~1GB).


2 Answers

Just as I have tested earlier on:

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> /* <![CDATA[ */  var aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 'test'; alert(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa );  /* ]]> */ </script> </body> </html> 

This script works as per fine. The variable name is longer than 512 characters.

My guess is that since Javascript is a interpreted language (or aka scripting language), the variable name length does not matter as long as it refers to a defined variable.

like image 152
mauris Avatar answered Sep 27 '22 20:09

mauris


I've tried the example above, x10 the amount of characters, then again, then again, then again.

When the variable length is of 513k characters, my Notepad++ is slugging along like a snail. Yet when I managed to save the file and run it locally, the alert appears without any delay.

Tested on: Chrome 19.0.1084.52, IE9, FireFox 11.0, Safari 5.1.5, Opera 11.62

Since JSBin only allows a maximum of 65535 characters within the <script></script> tags, I only managed to create a page with a 32.5k length variable: http://jsbin.com/ukunow/10

like image 42
Pacerier Avatar answered Sep 27 '22 21:09

Pacerier