google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






Vài kĩ thuật viết mã JavaScript cơ bản Bài viết JavaScript này hướng dẫn bạn vài kĩ thuật lập trình ứng dụng JavaScript, ứng dụng web đơn giản nhưng khá hiệu quả để có mã nguồn JavaScript tối ưu. Các kĩ thuật được đề cập trong bài viết hướng dẫn sử dụng JavaScript này là: hàm, các vòng lặp, toán tử, cách chú thích, ... Vui lòng vào bài viết chi tiết để xem thêm.


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

Javascript Looping

The For Loop

You use looping to perform an action over and over again. One of the ways you can loop, is to use what is called a for loop. A for loop continues performing actions until a condition is met. This is the basic structure of a for loop:

for (initial expression; condition to be met; edit the value of expression)
{
... javascript code...
}

An example of a real for loop looks like this:

for (var i = 1; i < 100; i++)
{
document.writelin(i);
}

The above code performs the following actions:

  • Create a variable i and assign it an initial value of 1
  • Define that the code below will be performed over and over until i is no longer less than 100
  • i++, is shorthand for add 1 to i. This action will be preformed after the code below is run through. So, the first number printed will be the number 1.
  • The code document.writelin(i); prints the value of i on the browser screen. document.writeln, is a prebuilt function for writing to the browser screen and it is ended with a semicolon (;)
  • The curly braces are used to define the code that needs to be performed over and over again.

The While Loop

A while loop can also be used for looping. It's basic structure is:

while (condition)
{
... code...
iterator
}

An example of a real while loop:

while ( i < 100)
{
document.writelin(i);
i++;
}

It performs the same action as the previous for loop.

The Do-While Loop

The Do-While loop is almost identical to the while loop except it doesn't check if the condition has been met before executing the code in curly braces first. It's basic structure is:

do {
... code...
}
while ( i < 100 )

An example of a real do-while loop:

var i = 1;
do{
document.writelin(i);
i++;
}
while( i < 100 )

This code performs the same exact actions as the previous for and while loop.

The For-In Loop

The final looping tool may be a little confusing. Everything in Javascript is considered an object. Objects have variables and functions that they can perform. Programming languages used to be called procedural languages because they mainly performed an action and then another over and over again. Then a new form of programming was invented called object oriented programming. Through OOP, you instead create a bunch of objects that interact with each other. I'll dive more into this subject later, but I thought I should explain OOP before I dive into the next loop.

You use the for-in loop for looping through all of the variables of an object. If you have variables assigned to an object you created, this loop cycles through them. Here is the basic structure of a for-in loop:

for (var objectVariable in objectItself)
{
... code...
}

Here is a real example:

for (var objectVariable in objectItself)
{
infoOnObject = objectName + "." + objectVariable + " = " + objectItself[objectVariable];
document.writelin(infoOnObject);
}

If the previous code is confusing, skip it and we'll come back to it later. Otherwise, this is what it is doing:

  • The for-in loop, loops through all of the variables of the object, which is named "objectItself"
  • Each time it finds a new variable it assigns that variable to the variable objectVariable
  • Then the name of the objects variable and the value of that variable are combined and stored in the variable infoOnObject
  • Then the function document.writelin prints out the variable name and variable value, to the browser screen. Ex. "variable1 = 23″

We'll talk a lot more about objects later. Don't worry if you didn't totally grasp this one concept.

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