google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






2 thủ thuật hiệu quả với mệnh đề điều kiện If trong JavaScript Tìm hiểu thêm về việc sử dụng điều kiện If trong JavaScript thông qua bài hướng dẫn đơn giản này, qua đó bạn có thể nắm vững cách sử dụng mệnh đề If trong JavaScript sao cho chương trình JavaScript được tối ưu nhất.


Miễn phí web hosting 1 năm đầu tại iPage



Nếu bạn vẫn còn đang tìm kiếm một nhà cung cấp hosting đáng tin cậy, tại sao không dành chút thời gian để thử với iPage, chỉ với không quá 40.000 VNĐ/tháng, nhưng bạn sẽ được khuyến mãi kèm với quà tặng trị giá trên 10.000.0000 VNĐ nếu thanh toán cho 24 tháng ~ 900.000 VNĐ?

Có trên 1 triệu khách hàng hiện tại của iPage đã & đang hài lòng với dịch vụ, tuyệt đối chắc chắn bạn cũng sẽ hài lòng giống họ! Quan trọng hơn, khi đăng ký sử dụng web hosting tại iPage thông qua sự giới thiệu của chúng tôi, bạn sẽ được hoàn trả lại toàn bộ số tiền bạn đã sử dụng để mua web hosting tại iPage. Wow, thật tuyệt vời! Bạn không phải tốn bất kì chi phí nào mà vẫn có thể sử dụng miễn phí web hosting chất lượng cao tại iPage trong 12 tháng đầu tiên. Chỉ cần nói chúng tôi biết tài khoản của bạn sau khi đăng ký.

Nếu muốn tìm hiểu thêm về ưu / nhược điểm của iPage, bạn hãy đọc đánh giá của ChọnHostViệt.com nhé!
Thử iPage miễn phí cho năm đầu tiên NGAY

Just a quick post, inspired by Laura Kalbag's post, which included this gem:

We shouldn't be fearful of writing about what we know. Even if you write from the most basic point of view, about something which has been 'around for ages', you'll likely be saying something new to someone.

One: There is no else if

When you write something like this ...

function saySomething( msg ) {
  if ( msg === 'Hello' ) {
    console.log('Hello there');
  } else if ( msg === 'Yo' ) {
    console.log('Yo dawg');
  }
}

... then what you're actually writing is this ...

function saySomething( msg ) {
  if ( msg === 'Hello' ) {
    console.log('Hello there');
  } else {
    if ( msg === 'Yo' ) {
      console.log('Yo dawg');
    }
  }
}

That's because there is no else if in JavaScript. You know how you can write an if statement without any curly braces?

if ( foo ) bar() // please don't do this if you want your code to be legible

You're doing the same thing with the else part of the initial if statement when you write else if: you're skipping the curly braces for the second if block, the one you're providing to else. There's nothing wrong with else if per se, but it's worth knowing about what's actually happening.

Two: return Means Never Having to Say else

Consider some code like this:

function howBig( num ) {
  if ( num < 10 ) {
    return 'small';
  } else if ( num >= 10 && num < 100 ) {
    return 'medium';
  } else if ( num >= 100 ) {
    return 'big';
  }
}

If the number we pass to howBig is less than 10, then our function will return 'small'. As soon as it returns, none of the rest of the function will run – this means we can skip the else part entirely, which means our JavaScript code could look like this:

function howBig( num ) {
  if ( num < 10 ) {
    return 'small';
  }

  if ( num < 100 ) {
    return 'medium';
  }

  if ( num >= 100 ) {
    return 'big';
  }
}

But wait – if the first if statement isn't true, and the second if statement isn't true, then we will always return 'big'. That means the third if statement isn't even required:

function howBig( num ) {
  if ( num < 10 ) {
    return 'small';
  }

  if ( num < 100 ) {
    return 'medium';
  }

  return 'big';
}

From

Link: http://rmurphey.com/blog/2012/12/10/js-conditionals

iPhoneKer.com
Save up to 630$ when buy new iPhone 15

GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project

https://tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools

chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
Talk to ChatGPT by your mother language

Dall-E-OpenAI.com
Generate creative images automatically with AI

AIVideo-App.com
Render creative video automatically with AI

JavaScript theo ngày


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web