Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm fairly new to Javascript, and filled with questions, most of which I'm able to find the the answers to online. However, there is the rare occurrence when my wording of a question doesn't correctly communicate the idea I'm trying to portray. That's when I come to Stack Overflow, and try to communicate more visually.
Which of these two examples is more commonly acceptable when programming with Javascript?
Method 1:
var one = 1;
var two = 2;
Method 2:
var one=1,
two=2;
Are there more specific (organizational) occasions when Method 2 should be used?
Example:
// Food
var pizza,
sushi,
cheeseburger;
// Utensils
var fork,
spoon,
excalibur;
Just in-case you believe the answer to this question is purely subjective, I pose a different question for you: which way (in terms of storage) is more efficient, and is the size of the difference insignificant for larger-scale web apps?
The virtual machine treats the two identically. There will be no performance difference between the two. Stylistically some developers prefer the former, while I have always used the latter. Ultimately whatever you find more readable and whatever is the communalized standard at your organization is the one to go with.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
What exactly is a "List" in JavaScript?
I got asked this question and I'm a professional of five years but this made me fumble.
I understand Arrays, Stacks, Queues, even Linked Lists.
But isn't a List just an Array in JavaScript? Because then I got asked what the difference between a List and an Array was, and I said no difference - and never got to know if that was right.
I understand the differences between the data structures List and Array in C# and Python but I don't get this one for JavaScript.
I understand the downvotes ... it was indeed a dumb question, I think I should have known that Lists weren't a type in JavaScript and tackle the dumb question that way.
For anyone this may prove useful: For front-end engineer interviews, make sure you know that JavaScript is a dynamic language, meaning the data structures are very different from static typed languages like C and Java, and even have different meanings in Python even though Python is a dynamically typed language similar to JavaScript.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Should i have one constants file for the whole app or split it one for each coresponding store , action ?
My thought's are one for the whole app?
It's a matter of preference.
If you have a couple dozen constants, I don't see a downside to keeping them in one file. If you have, say, hundreds of constants it may make sense to split them up—not for any technical reason, but just to make it easier for you and your teammates to find the ones you're looking for without digging through many pages of the same file.
Either way you should do your best to group them logically—and even in a file as simple as a list of constants, generous whitespace and comments will make everyone's lives easier.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I was learning javascript from codecademy today.
There is one thing that confuse me a lot, in its tutorial, it use function names like orangeCost. like in this link:
http://www.codecademy.com/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661
In my behaviour, I feel both orange_cost and OrangeCost just fine.
Why in this broadly read tutorial, they use such variable name(orangeCost)?
Is there some history in it, or it can prevent some kind of catastrophe?
It's just a human convention.
In other environments, instead of using camel-casing, they use pascal-casing (orangeJuice would be camel-casing while OrangeJuice pascal-casing).
Conventions are powerful to let others understand our code as it's written in a standarized way.
It could happen that some convention would be ugly, but it's better to follow a convention than going alone the way.
Anyway, either camel or pascal casing aren't ugly per se. It's just our taste what turns something into ugly or beautiful.
An exception to the rule
Brainfuck code is ugly. I believe that there's a human convention about this ;)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
One of the interviewers asked to impress him with the JavaScript and CSS skills. He provided a link to two websites and asked to write a JavaScript application (page or pages) that takes content from one or both of these websites and demonstrates my command of jQuery and CSS. It doesn’t have to be useful to end-users, but it should be interesting to programmers.
What interesting things should I write? What would impress you in the candidate?
P.S.
The sites have real-estate information.
So, what would be the best way to read information from a given URL and extract some of it using jQuery?
That interview question is so subjective. What impresses one person might be basic to another. Why not ask a more meaningful question that demonstrates whether or not the candidate actually knows the language.
With all that said and if you really want to work for this company, I would study up on the basics of both js and jquery and really learn how to optimize basic functions. If you had to impress me then you should try to optimize a block of code as best you can without making the code unreadable. There's nothing better than clean, fast and readable code.