Results 1 to 2 of 2

Thread: Just some questions about Javascript

  1. #1
    Join Date
    Feb 2003
    Location
    Bandar Tasik Selatan, Malaysia
    Posts
    25
    Rep Power
    0

    Just some questions about Javascript

    More question about javascript syntax:
    1. Should I put else or not?

    if (tmpWeight <= 0.5)
    {
    tmpTotalPrice = '6';
    }
    {
    tmpTotalPrice = 6 + (parseInt((tmpWeight * 10) - 5));
    }

    if (tmpWeight <= 0.5)
    {
    tmpTotalPrice = '6';
    }
    else
    {
    tmpTotalPrice = 6 + (parseInt((tmpWeight * 10) - 5));
    }

    2. Why I see most javascript indention not too readable?

    the open curly bracket is at the end of the condition
    like
    if (tmpWeight <= 0.5) {
    ...
    }
    instead of
    if (tmpWeight <= 0.5)
    {
    ...
    }

    3. Should we put semicolon at the end of the statement? I think put or not put also no difference.

    4. if a > 1 and if (a > 1) got difference? I think bracket is being used when we want to prioritise certain condition only or that is a syntax.

    Just hope to get Javascript more clearer. Thanks.

  2. #2
    Join Date
    Jul 2001
    Location
    KL, Malaysia
    Posts
    277
    Rep Power
    223
    1. Use else. Without else, the computer will do the unnecessary processing everytime.

    2. This is individual preference. I always put the open bracket on the same line to have less lines, shorter page length.

    3. I always put semicolon.

    4. I always put brackets for if-else condition. Will it always work if we obmit the brackets? No idea, never test before.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Questions about the User CP
    By imranies in forum FeedBack & Suggestion
    Replies: 7
    Last Post: 01-04-2009, 05:09 PM
  2. Replies: 1
    Last Post: 20-04-2008, 04:09 PM
  3. Questions~
    By wingwp in forum FeedBack & Suggestion
    Replies: 1
    Last Post: 24-11-2007, 12:34 AM
  4. Questions regarding Hosting
    By kenspear in forum Paid Hosting Discussion Forum
    Replies: 3
    Last Post: 29-05-2007, 10:35 PM
  5. Questions on PayPal
    By stephen in forum E-Commerce
    Replies: 4
    Last Post: 06-09-2005, 11:25 PM

Posting Permissions

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

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32