Javascript [Electronic resources] : The Definitive Guide (4th Edition) نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Javascript [Electronic resources] : The Definitive Guide (4th Edition) - نسخه متنی

David Flanagan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


6.19 The Empty Statement




One final legal statement in
JavaScript is the empty statement. It looks like this:

;

Executing the empty statement obviously has no effect and performs no
action. You might think there would be little reason to ever use such
a statement, but the empty statement is occasionally useful when you
want to create a loop that has an empty body. For example:

// Initialize an array a
for(i=0; i < a.length; a[i++] = 0) ;

Note that the accidental inclusion of a semicolon after the right
parenthesis of a for loop,
while loop, or if statement can
cause frustrating bugs that are difficult to detect. For example, the
following code probably does not do what the author intended:

if ((a == 0) || (b == 0));   // Oops! This line does nothing...
o = null; // and this line is always executed.

When you intentionally use the empty statement, it is a good idea to
comment your code in a way that makes it clear that you are doing it
on purpose. For example:

for(i=0; i < a.length; a[i++] = 0) /* Empty */ ;  

/ 844