SitePoint Sponsor

User Tag List

Results 1 to 18 of 18

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Location
    Pabna, Bangladesh
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Some definitions of JavaScript

    What is string?
    What is parameter?
    What is parentheses () ?

    Please see the following codes:

    <html>
    <head>
    <script type="text/javascript">
    function show_prompt()
    {
    var name=prompt("Please enter your name","Harry Potter");
    if (name!=null && name!="")
    {
    document.write("Hello " + name + "! How are you today?");
    }
    }
    </script>
    </head>
    <body>

    <input type="button" onClick="show_prompt()" value="Show a prompt box" />

    </body>
    </html>


    name!=null && name!="" is included here.
    Here what is the meaning of null?
    Here what is the meaning of ?

    Thank you.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,873
    Mentioned
    208 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Quote Originally Posted by foysalu9 View Post
    What is string?
    A sequence of characters.

    Quote Originally Posted by foysalu9 View Post
    What is parameter?
    When you call a function, you can pass along some values to it, these values are called arguments or parameters.

    Quote Originally Posted by foysalu9 View Post
    What is parentheses () ?
    Round brackets.

    Quote Originally Posted by foysalu9 View Post
    Here what is the meaning of null?
    No value.

    Quote Originally Posted by foysalu9 View Post
    Here what is the meaning of ?
    An empty string.

    What the function is doing is checking to see if the variable name contains a sensible value before writing its output to the screen.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Location
    Pabna, Bangladesh
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    Thank you so much for your response.

    I am happy to say that your answers help me a lot.

    I hope you will help me in future again.

    Thank you again.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Pullo View Post
    When you call a function, you can pass along some values to it, these values are called arguments or parameters.
    Strictly speaking parameters are the values passed to a function when the function is called and arguments are the placeholders used to define how those values will be used in the function itself.


    Code:
    function myfunc(a, b, c) { // a, b, and c are arguments
    ...
    }
    
    myfunc(x,y,z); // x, y, and z are parameters
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,873
    Mentioned
    208 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by felgall View Post
    Strictly speaking parameters are the values passed to a function when the function is called and arguments are the placeholders used to define how those values will be used in the function itself.
    Oh wow, I didn't know that. Thank you!

    That actually leads me to a second question: in JavaScript terms, is there a difference between a method and a function, or are these two terms synonymous?

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Pullo View Post
    That actually leads me to a second question: in JavaScript terms, is there a difference between a method and a function, or are these two terms synonymous?
    Strictly speaking JavaScript doesn't have functions or methods - it only has objects and properties.

    All "functions" that are defined directly are "methods" of the window object (or whichever object they are defined inside of) and all "methods" in JavaScript are in fact objects in their own right since they too can have properties and "methods" defined for them.

    In practical terms it makes sense to refer to any methods where you don't specify the object that it belongs to are effectively working as functions and any where you define them as belonging to a specific object but don't attach any properties or additional objects to it are effectively working as methods. Neither situation is entirely clear cut though - particularly if you start defining "methods" on the Function object and run that against all the "functions" in your page.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,873
    Mentioned
    208 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by felgall View Post
    Strictly speaking JavaScript doesn't have functions or methods - it only has objects and properties ...
    Thank you for your explination, felgall.
    I've been doing a little more reading on the subject and stumbled upon this StackOverflow discussion of the same question (although not related especially to JavaScript).

    I found it quite interesting reading, if not a little confusing and contradictory in places.

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    ...parameters are the values...arguments are the placeholders...
    It's actually the other way around.

    Though, distinctions such as this only ever seemed to matter in school. In real life, I most frequently hear people use "parameters" to describe both.
    "First make it work. Then make it better."

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    It's actually the other way around.
    When did they reverse it? I clearly remember being taught that the arguments are the placeholders in the function and that you call a function using parameters some time back in the late 1970s or early 80s. I even have books from back then that refer to them that way around. I'd have to check but I am fairly sure that I also have some more recently published books that refer to them that way around as well.

    I agree with you that in practice the distinction between the two is effectively irrelevant and most people use either name to refer to both without it leading to misunderstandings (although it does appear that such usage has led to the meanings getting reversed at some stage).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Location
    Pabna, Bangladesh
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thank you so much for your help. I hope you will help me future again. Keep well.

  11. #11
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    If ever it was the other way around, then that was before my time.

    In Java, parameters are the variables when you declare a method, and arguments are the values when you invoke it. Perl is the same way. Wikipedia describes it this way as well.
    "First make it work. Then make it better."

  12. #12
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    If ever it was the other way around, then that was before my time.
    It definitely was the other way around when JavaScript was created as the JavaScript construct that you use within functions as a placeholder list to access all the values passed to the function is called arguments[] - if it were the way around that you suggest then it would have been called parameters[]

    So effectively you can say that for JavaScript at least the two terms are the way around that I specified even if some languages have reversed the meanings.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  13. #13
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    It definitely was the other way around when JavaScript was created as the JavaScript construct that you use within functions as a placeholder list to access all the values passed to the function is called arguments[] - if it were the way around that you suggest then it would have been called parameters[]
    Ish. When you access arguments[], you're accessing the values that were passed in... which are referred to as arguments. For example, if a function is defined with one placeholder but invoked with 10 values, then arguments[] will hold 10 values, which means it represents the values passed in (the arguments) and not the placeholders.

    Also, ECMA-script defines the syntax this way:

    CallExpression Arguments

    function Identifier ( FormalParameterListopt ) { FunctionBody }
    "First make it work. Then make it better."

  14. #14
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my first time hearing when a function is invoked/called the parameters are being passed as values, instead of referring function invocations as arguments being passed. I may have to get some research on this.


Tags for this Thread

Bookmarks

Posting Permissions

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