...

View Full Version : Something I dare not very well submit to the "post a javascript thread"



goalsurfer
01-09-2012, 10:21 PM
<script language="javascript">
<!--
var getal = 10;
getal += 5;
getal /=3;
getal *= 2;
getal -= 2;
getal++;
document.write(getal);
//-->
</script>

It's not only because I don't know if this is a real script, but also it comes from a Belgian site in Dutch. Of course there exist browser translators now, so that problem is no real problem. Maybe it is interesting to learn what the getal++ does in this script where there is no if function. Because it DOES something, be certain about that.

Fou-Lu
01-09-2012, 10:48 PM
?
++ is a post-increment operator. It doesn't need to be in a an evaluation, so I'm not sure if I follow you.

As for this script, it serves no real purpose. Just through a 9 in there instead and away you go.

felgall
01-10-2012, 09:35 PM
It is also very old in the way it is written.

language="javascript" became obsolete many years ago (replaced by type="text/javascript" which itself is deprecated and to be replace by type="application/javascript" just as soon as IE8 dies - since the correct type doesn't work with JScript and IE8 and earlier don't run JavaScript).

<!-- and //--> are there to hide the script from Internet Explorer 2 and Netscape 1.

Fou-Lu
01-10-2012, 11:07 PM
It is also very old in the way it is written.

language="javascript" became obsolete many years ago (replaced by type="text/javascript" which itself is deprecated and to be replace by type="application/javascript" just as soon as IE8 dies - since the correct type doesn't work with JScript and IE8 and earlier don't run JavaScript).

<!-- and //--> are there to hide the script from Internet Explorer 2 and Netscape 1.

I was thinking the same thing. Even as an exclusive server side writer, even I can identify obsolete javascript code. The one that actually irked me was the document.write.
Its been too many years for JS for me.

Inigoesdr
01-11-2012, 04:46 AM
For funsies: http://jsfiddle.net/CB5Bd/

felgall
01-11-2012, 11:42 PM
The one that actually irked me was the document.write.

I agree, the only use for document.write disappeared with Netscape 4 as well.

Now there is innerHTML and the DOM either of which will produce far less obtrusive code.

capypara
01-13-2012, 10:58 AM
Just in case you still do not understand what the script does, its not doing anything amazing other than simple maths. getal is nothing more than a variable name since we are all coding in English anyway, so any other language in a programming code serves no purpose other than comments.

goalsurfer
01-13-2012, 08:44 PM
What's the difference between 'deprecated' and 'obsolete'?

felgall
01-14-2012, 12:19 AM
What's the difference between 'deprecated' and 'obsolete'?

'deprecated' means that there are better ways to do it now and this way will be removed completely in the next version so it will no longer work at all once the next version comes out unless you update to use the better way before then.

'obsolete' doesn't imply that it is going to be removed and so it will continue to work in the future even though there are better alternatives.

goalsurfer
01-17-2012, 11:37 AM
corrigating

correcting

goalsurfer
01-17-2012, 12:19 PM
I agree, the only use for document.write disappeared with Netscape 4 as well.


Somewhere I had that impression already.

goalsurfer
01-18-2012, 12:00 PM
Fou-Lu and felgall,
1. "<!-- //-->" I only started using recently because I saw that in all JavaScripts I met. Oh, I can just drop that?
2. Instead of "document.write", what about "window.alert"?
3. The use of "++" I learned earlier (2003 - '04).
4. This "script" comes from [non english .be site].

Capypara, between brackets "getal" means "number". The way [non english .be site] displays its educational scripts it is as if in JavaScript you may just change the value of your variables, JavaScript will only take in account the latest value you assign to a variable. I made already some very interesting conclusions there.

Fou-Lu
01-18-2012, 07:42 PM
Last time I used JS you would accommodate the commenting via XHTML compliant cdata blocks. Since XHTML is no longer the accepted, I have no idea what JS uses anymore.
Those serve different purposes. Document.write should be replaced by dom manipulation instead.
What I meant in total here is that the entire block serves no real purpose. There is no dynamic data gathering, so a simple document.write(9) is exactly the same as all the operations performed above. Above this, I was referring to the unary aspect of the pre/post increment operator. I'm still not sure what you are meaning about it being in an evaluation block; ++x doesn't change what it does whether it is within a stand alone, a comparison block, or loop. The latter two will control if the actual increment occurs though.
Doesn't really matter where it came from. IMO one of the most important thing to learn about any language is what is obsolete / obsolescent so that you can date the age of examples. If you see document.write within a tutorial (unless the tutorial's specific purpose is to teach what document.write does), this indicates that the code provided is obsolete, and that the tutorial you are reading can probably be done better than when it was written.
This entire concept is one of my #1 gripes of people purchasing books to learn from. These become obsolete so fast that while learning the code you have no idea that the code you are being taught it effectively worthless.

felgall
01-18-2012, 09:40 PM
window.alert is a debugging tool. Some browsers include a checkbox for turning JavaScript off for that web page and tohers provide a way to disable all future alerts.

Modern JavaScript has a whole series of commands (known as the Document Object Model - or DOM) for interacting with web pages.

If you haven't used JavaScript for some years it might be faster to forget all what you know and start learning it all over again as modern JavaScript has very little in common with scripts written for Netscape 3 and IE3 (which for some reason is still the way a lot of people are teaching others to write their scripts).

The CDATA tag around Javascript is only necessary if you serve your page as XHTML. XHTML is very much alive and is getting closer to being actually practical to use since IE started supporting it with IE9. The new version currently under development is called XHTML5. XHTML 1.0 will be practical to use long before (X)HTML5 is as we just need to wait for IE8 to die to use XHTML whereas no browser currently supports HTML5 because the standard isn't even finished yet for the browsers to know what they need to support.

The best way to attach your JavaScript to a web page is to place it all in an external file and link it with a script tag immediately before the </body> tag. That way you don't need to concern yourself with wrapping anything around it to hide it from anything. It also allows the web page to load faster and for the script to run sooner than if you attach it in the <head>.

goalsurfer
01-19-2012, 03:28 PM
Well, now I know in any case where to start to update my knowledge.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum