This question already has answers here:
Variable name length vs performance
(2 answers)
Closed 6 years ago.
Is it possible that a long method or variable name slows down your javascript program a bit?
I wanted to ask because I am currently working on a program where i have a very long method identifier and I wonder if I should shrink it. It would however make my code not so clear anymore.
I know it doesn't matter for compiled languages but what about javascript?
P.S. I do not plan to use a minifier.
Generally, function name length, variable name length, etc, should have no bearing on performance, unless you're talking name length in hundreds of thousands of characters.
Related
This question already has answers here:
Is it possible to sandbox JavaScript running in the browser?
(15 answers)
Closed 3 years ago.
I'm aware similar questions have been asked before, but my use-case is a little different.
I'd like to create an educational app similar to LeetCode, CodeWars, etc. where users can type in their own functions to solve algorithms.
Right now, I'm focusing on JavaScript, so the code could be evaluated on client-side.
I want to know, what considerations should I take into account to use eval() and new Function() safely?
Or is there a better alternative?
Luckily you're not alone, and someone invented the wheel before you. You can check out NeilFraser/JS-Interpreter or sandbox.
There may be even better documented/implemented solutions that I'm not aware of, but it's a good start.
This question already has answers here:
How do I check if a variable is an array in JavaScript?
(24 answers)
How can I check if an object is an array? [duplicate]
(51 answers)
Closed 3 years ago.
I was reading this question about how to check if a variable is an Array in Javascript, and this answer proposes several solutions:
1. variable.constructor === Array
2. Array.isArray(variable)
3. variable instanceof Array
The post has several updates and they touch on the efficiency of the different solutions, but between the post and its comments it isn't entirely clear which solution is the most efficient. I'm hoping to clarify which of these solutions provides the most efficient check for whether or not a variable is an Array in JavaScript.
Edit: I'd like to note that this question is about the performance of checking whether or not a variable is an Array and not how to check if a variable is an Array. Considering all the noise in the linked question, I believe there is value to the question.
Thanks to the comments I received, I realized I missed a link to a benchmark, which I then edited to determine that variable instanceof Array is the most efficient of the solutions I was asking about in my question when using Chrome 74. Here is the benchmark.
This question already has answers here:
CSS: What does the question mark at the end of css do?
(7 answers)
What does "styles.css?=121" mean in this html code? [duplicate]
(2 answers)
Closed 8 years ago.
Why do use like this filename.css?2 or filename.js?4
What are those numbers after question mark?
I did research online but I didn't find any answer.
Thanks!
These are called cache busters.
Usually, when a browser downloads a file (CSS, JS, etc.) it caches it so that it doesn't have to download it later.
However, this is a problem when you decide to update your file, because the browser thinks it already has the latest version. To work around it, we use the cache busters. When you make a change to the file, you also change the number after the question marks, which tricks the browser into thinking this is a different file for which it doesn't have a cache it, and forces a re-download.
Sometimes JS scripts are created on the fly using server side technologies other times it is simply a version number to help with browser caching issues
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
javascript test for existence of nested object key
In JavaScript, is there an easier way to check if a property of a property exists?
I've been searching for an elegant way to verify if the entire object path is defined.
For example: person.positions.values[0].company.name
On every step of the way, after the person, it can be undefined.
Can this be done without actually going through them one by one?
Thank you.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Huge Integer JavaScript Library
Suppose I want the exact value for 2^1000. How am I supposed to get the entire value? Maybe storing it in a string every time the multiplication is done, but it will still eventually go over 10 digits! Is there any way, or does ECMAScript just not support this?
Math.pow(2,1000)
returns
1.0715086071862673e+301
how accurate do you need this to be?