开发者

Is there any line limitation in javascript?

开发者 https://www.devze.com 2023-02-27 09:26 出处:网络
is t开发者_如何学Chere any limitation on number of lines a javascript file can have? 10121 / 8 Since 10121 is the maximum number of bits in the universe and presumably you would do 8-bit encoding of

is t开发者_如何学Chere any limitation on number of lines a javascript file can have?


10121 / 8

Since 10121 is the maximum number of bits in the universe and presumably you would do 8-bit encoding of your javascript, then even if the whole universe was filled with nothing else then your blank javascript file there could be no more then 11.25e120 lines in it.

TL;DR No there is no limit.


Nothing official, but the larger the file, the more the browser needs to download, parse and execute.

In fact, a common practice it to join multiple javascript files into one so only one browser connection gets tied up with downloading javascript. This is normally part of minification (which can include other steps such as renaming variables to short ones, removing whitespace etc...).


I don't think there's an actual line number limitation for a javascript file, but obviously the number of lines and amount of javascript code you have can greatly affect performance.

So, the fact that you're asking this at all might be a reason to optimize and examine the code itself. Perhaps splitting out certain code functions that aren't needed on every page into different files could ease the load.


Actually there is, if you are running in IE you will find that a program that runs over more than 5,000,000 lines. IE thinks it may be stuck in a endless loop and a popup will prompt the user to either kill the script or continue...


Nope :-)

The only limitation is the memory of the computer it is running on, or the software running the Javascript. There are no such limitations in the design of Javascript.

However...

If you have tens of thousands of lines of code, you may wish to evaluate your design and refactor a lot of it as it can be a sign of badly designed code.

0

精彩评论

暂无评论...
验证码 换一张
取 消