www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: java scripts from hell help please

  1. #16
    Join Date
    Nov 2010
    Posts
    1,047
    Quote Originally Posted by deathshadow View Post
    But really the big glaring error is that you seem to be trying to call the function "cube" BEFORE YOU'VE DECLARED IT! If you're not inside a object, and you haven't declared it yet, it doesn't EXIST! You can't call 'cube' or 'average' before you have declared them! Their function declarations MUST go before you call them.
    This is not strictly true - if the function is named and declared using the function keyword (as teranova does with the cube function) it can be called at any point because the identifier is bound before the code block runs on the first run of the compiler. If you were assiging an anonymous function to a variable the code would fail...

    Code:
    <script>
    callIt();
    
    function callIt(){
    alert("callIt works");
    }
    
    try {
    callItagain();
    } catch (e){
    alert("callItagain doesn't work");
    }
    
    var callItagain = function () {
    alert("callItagain works");
    }
    
    
    </script>
    it's hard to think of a use when calling a function before it is declared would be really useful/necessary and it's definitely a bad habit to get into, but to me it seems to be just one of those little areas where javascript is alot more forgiving than other languages
    Last edited by xelawho; 05-19-2014 at 10:36 AM.

  2. #17
    Join Date
    May 2014
    Posts
    10
    so from those 3 codes can u guys tell me whats wrong with them as i need get them working by tomoz :O

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles