Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Location
    Brussels Belgium
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    ?
    ++ 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.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Last edited by felgall; 01-10-2012 at 08:38 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    New Coder
    Join Date
    Aug 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New to the CF scene
    Join Date
    Nov 2009
    Location
    Brussels Belgium
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    temporary reply

    What's the difference between 'deprecated' and 'obsolete'?

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    New to the CF scene
    Join Date
    Nov 2009
    Location
    Brussels Belgium
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by goalsurfer View Post
    corrigating
    correcting

  • #11
    New to the CF scene
    Join Date
    Nov 2009
    Location
    Brussels Belgium
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #12
    New to the CF scene
    Join Date
    Nov 2009
    Location
    Brussels Belgium
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    goalsurfer (01-19-2012)

  • #14
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    goalsurfer (01-19-2012)

  • #15
    New to the CF scene
    Join Date
    Nov 2009
    Location
    Brussels Belgium
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Well, now I know in any case where to start to update my knowledge.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •