Go Back   CodingForums.com > :: Computing & Sciences > Geek News and Humour

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2012, 09:21 PM   PM User | #1
goalsurfer
New to the CF scene

 
Join Date: Nov 2009
Location: Brussels Belgium
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
goalsurfer is an unknown quantity at this point
Something I dare not very well submit to the "post a javascript thread"

<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.

Last edited by goalsurfer; 01-09-2012 at 09:27 PM.. Reason: corrigating human language
goalsurfer is offline   Reply With Quote
Old 01-09-2012, 09:48 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,649
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
?
++ 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.
Fou-Lu is offline   Reply With Quote
Old 01-10-2012, 08:35 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 01-10-2012 at 08:38 PM..
felgall is offline   Reply With Quote
Old 01-10-2012, 10:07 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,649
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by felgall View Post
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.
Fou-Lu is offline   Reply With Quote
Old 01-11-2012, 03:46 AM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
For funsies: http://jsfiddle.net/CB5Bd/
Inigoesdr is offline   Reply With Quote
Old 01-11-2012, 10:42 PM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Fou-Lu View Post
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-13-2012, 09:58 AM   PM User | #7
capypara
New Coder

 
Join Date: Aug 2011
Posts: 49
Thanks: 1
Thanked 0 Times in 0 Posts
capypara is an unknown quantity at this point
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.
capypara is offline   Reply With Quote
Old 01-13-2012, 07:44 PM   PM User | #8
goalsurfer
New to the CF scene

 
Join Date: Nov 2009
Location: Brussels Belgium
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
goalsurfer is an unknown quantity at this point
temporary reply

What's the difference between 'deprecated' and 'obsolete'?
goalsurfer is offline   Reply With Quote
Old 01-13-2012, 11:19 PM   PM User | #9
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by goalsurfer View Post
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-17-2012, 10:37 AM   PM User | #10
goalsurfer
New to the CF scene

 
Join Date: Nov 2009
Location: Brussels Belgium
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
goalsurfer is an unknown quantity at this point
Quote:
Originally Posted by goalsurfer View Post
corrigating
correcting
goalsurfer is offline   Reply With Quote
Old 01-17-2012, 11:19 AM   PM User | #11
goalsurfer
New to the CF scene

 
Join Date: Nov 2009
Location: Brussels Belgium
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
goalsurfer is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
I agree, the only use for document.write disappeared with Netscape 4 as well.
Somewhere I had that impression already.
goalsurfer is offline   Reply With Quote
Old 01-18-2012, 11:00 AM   PM User | #12
goalsurfer
New to the CF scene

 
Join Date: Nov 2009
Location: Brussels Belgium
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
goalsurfer is an unknown quantity at this point
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.
goalsurfer is offline   Reply With Quote
Old 01-18-2012, 06:42 PM   PM User | #13
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,649
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
  1. 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.
  2. Those serve different purposes. Document.write should be replaced by dom manipulation instead.
  3. 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.
  4. 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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
goalsurfer (01-19-2012)
Old 01-18-2012, 08:40 PM   PM User | #14
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,453
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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>.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
goalsurfer (01-19-2012)
Old 01-19-2012, 02:28 PM   PM User | #15
goalsurfer
New to the CF scene

 
Join Date: Nov 2009
Location: Brussels Belgium
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
goalsurfer is an unknown quantity at this point
Well, now I know in any case where to start to update my knowledge.
goalsurfer is offline   Reply With Quote
Reply

Bookmarks

Tags
script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:57 PM.


Advertisement
Log in to turn off these ads.