The Javascript Blues [☝]

Sunday, July 13, 2014

For the past year, I have been working with a fairly new programming language -- Javascript. My past work experience exposed me to Java (of which I'm still trying to get to know) so I am still new with Javascript. It's common misconception that these two languages are somehow the same, but I'm telling you otherwise. Working with Javascript gave me lots of surprises and shocks because it's logic is very different with that of Java.

* not all variables need to be declared
This one is a very basic syntax in Java, but Javascript does not follow it! You can just use variables out of the blue. The catch: those undeclared variables are stored in the global memory of the web browser and may use up unnecessary space. This site actually mentions this, with additional information on the best practices in Javascript.

* confusing logic: if (variable)
In Java, 0 = false, 1 = true. In Javascript null = false, not null = true. See example below.

2var testStr = '';
3
4if (test){
5testStr  = 'pasok!';
6} else {
7testStr   = 'hindi';
8}
9
10var i = 0;

With this logic, value of testStr is 'hindi'.

* -1=='-1' is true in Javascript
In JS, as long as the content is the same, even if the type is different, it's considered as equal.

These are just a few of the scenarios wherein Java and Javascript differ. Maybe I could list some more of the discoveries that I will make in the future.

I just have to say, I need to review my Java soon. I somehow miss programming with it.


  • Share:

You Might Also Like

0 (mga) komento

trazy.com