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 many languages, to find cosine, you use cos(x). But in JavaScript, you must use Math.cos(x). Why doesn't JavaScript spare us the 5 characters in Math., both making it easier to type and easier to read?
I have tried to Google this multiple times, and found no answers. Is there any practical reason for this that I have not yet found?
So far, there are three reasons I can think of:
The creators of JavaScript want to ensure that the math functions do not coincide with other functions users create (Like a function called 'cos()` that calculates, say, cosecant)
The creators of JavaScript thought that Math would make the code more readable
The creators of JavaScript perhaps didn't want any functions that have window as a parent (Though alert and prompt make this unlikely)
To hold the math functions without polluting the global namespace.
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 4 years ago.
Improve this question
Is there any resource to know the time complexity of natively defined array and string methods in JavaScript?
I have to do guess work while I am using them to solve algorithm, but I want to be sure about what is the time complexity of those functions?
This question has been answered previously:
Time Complexity for Javascript Methods in V8
In short, it's not specified and the time complexity for common JS methods can differ between browsers.
Worse yet, some methods might not even exist or will behave differently between different browsers and browser versions!
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 5 years ago.
Improve this question
my question why we initialize array in different ways.
as i initialize array in php like array();
and in javascript in different way.
please anyone explain difference between array() and Array().
Thanks.
The shortest answer is that they are completely different languages and, just as different spoken languages have different grammar and vocabularies from each other, so do programming languages.
Beyond that, every programming language has to have some sort of runtime or compiler that understands the syntax, data structures, processing model, etc. And, each of those environments are free to implement those details as they see fit. This means that how an Array is internalized can be quite different between languages. But, to the programmer, we don't really need (or care) to know those implementation details.
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 6 years ago.
Improve this question
I'm currently working on a web page where you can add many different "machines" and then specify certain things about each one.
My original thought was to create div's for each machine (which would contain common elements like "name", "operating system", etc), and then change the IDs according to the names. That being said, is this really the best approach? Is there some way to use javascript/jquery to essentially make classes?
I also read briefly about some javascript template libraries like mustache, but did not get too into them.
Not looking for you to write the code for me -- just wondering how I should approach this
Yes, you can use an array of JSON objects for this.
A Javascript library that supports model binding like AngularJS or Knockout can make displaying all the "machines" very easy with their foreach functionality.
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 am a Python programmer before learning Javascript, and as lowercase_separated_by_underscores is recommended for Python's variable naming,
I continued using it for programming Javascript since changing habit is painful and unconvenient. But after seeing a lot of
professional Javascript code which use lower camel case to name variables, I begin to think about
what is the most standard and suggested way, this_way or thatWay ?
The universally accepted naming convention for JavaScript is lowerCamelCase, yes.
Well, have you taken a look at the DOM API? Or the built-in objects? Here are some methods names...
getElementById
forEach
addEventListener
toLowerCase
This should answer your concerns.
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 5 years ago.
Improve this question
I'm trying to model my javascript object using visio, visio doesn't support javascript data types.
Then I start thinking, how do you desing model your javascript code?
Cheers
In the past, I've used Open Source tools like Dia and just fudged the data types where needed...
It's enough to get the idea across, but you're definitely not going to get anything even close to code generation from it.
I prefer Object Oriented design - even for JavaScript - so I suggest Rational Rose. I like some of the features of OO (e.g. encapsulation and abstraction) and like to add some discipline to a potentially undisciplined environment - especially when working with developers new to JavaScript. Rose meets my needs.