by coreyp_1 · 9y ago · 0 comments
Two things that many people get wrong about JavaScript: (1.) Most of the ugly parts involve interacting with the DOM, and the DOM is NOT JavaScript, and (2.) Just because some people write ugly code with it does not mean that the language itself is ugly.
ES6 and ES7 have done wonders for the language syntax, and the flexibility of the language allows you to write in any combination of procedural, functional, prototypical, object-oriented programming styles. I mix them together as needed to make programs more intuitive and easier to follow. Programming is an art, and JavaScript is a powerful and versatile tool.
You are also wrong in that it being the only language supported by browsers. That may be the case now, but in the past many, many, many websites used flash and java applets. Quite frankly, the reason that JavaScript is what we have now is because it really is that good that it replaced all the other options.
All of the other questions are all over the board... It sounds like you are trying to get us to write a homework assignment for you.
And JS beating flash and java applets may be more a result of market forces (Apple) and the lack of better alternatives.
Brendan Eich designed JS in 10 days for the early era of the web, which is very different today. Its both a testament to the language and the hacks on top of it that its stayed in use this long. But maybe its time to move on?
[1] https://medium.com/javascript-non-grata/javascript-is-a-dysf...
[2] https://en.wikipedia.org/wiki/JavaScript#Beginnings_at_Netsc...
Yeah, like dealing with "this" keyword or type coercion in JS is not the ugliest thing ever in the history of Programming languages
This can get a little confusing until you understand how context works. Then it makes sense but you know what? You don't always need to use this. In fact you can build entire applications in different ways without ever using this. And no writing without using this doesn't make your code ugly or unmanageable. There are just many ways to get the same or similar things done in JavaScript.
> type coercion in JS
Type coercion is ugly in any programming language. It's best to avoid it, even in JavaScript (which you can do, btw).
You can avoid type coercion if you understand how the language works (aka strict equality in JavaScript) but this isn't something only in JavaScript land either.
Try python. Python's handling of this/self makes javasacript look like the most amazing thing ever.
# so much text for such a little task
def length(self):
return math.sqrt(self.x*self.x + self.y*self.y + self.z*self.z)
# better, but not quite there yet
def length(self):
return math.sqrt(self.x**2 + self.y**2 + self.z**2)
# this would be perfect, but it's not allowed by python
def length():
return math.sqrt(x*x + y*y + z*z)
To be fair, javascript also forces you to explicitly specify "this" so there is no difference in that regard.
What I find worse than that is that you have to specify self in the parameter list.
Calling a function with 2 parameters but having to declare 3 doesn't make sense. The usuall reasoning is that "explit is always better than implicit" but I do not agree. We could take this philosophy all the way to explicitly defining all the global variables that may be used by the function in the parameter list, maybe even all the packages that this function is going to use. We don't do that for a good reason.Is it not always the object that owns the function currently being executed?
If the "this" is implicit, then how can you possibly know where the variable comes from?
This so not true. "this" is much wider paradigm in JS.
{} is new Object();
If you find "this" confusing you can and should avoid using it. JavaScript has many bad parts that some programmers love to use because it makes their code "elegant". It is however possible to write simple and easy to understand code by only using the good parts.
Elegant... hmmmmm
[].toString() === ""
It's only confusing to people who really don't know anything about the language.
Would you write that in production?