google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






Vài kĩ năng lập trình JavaScript cơ bản Mặc dù bài hướng dẫn JavaScript này không được viết bởi một chuyên gia về JavaScript nhưng nó vẫn chứa đựng nhiều thủ thuật JavaScript hữu ích có thể giúp bạn cải thiện kĩ năng lập trình JavaScript của mình.


Nhãn: kĩ năng lập trình JavaScript, chuyên gia, lập trình JavaScript

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

I am not an expert in Javascript. Though, I can share some points which are more significant when you use javascript in your applications.

  • Cache element property when access multiple times. In DOM, it's an extensive search of the element to find the same property over and over again. Perfect example is document object

var divelt = document.getElementById("div1″);
var img = document.getElementByTagName("img");

instead use

var doc = document
var divelt = doc.getElementById("div1″);

  • Use Local variables rather than Global variables, because local variables are fast, global variables are little performance penalty.

for(i=0; i < array.count; i++){
alert("array data : " +array[i]);
}

store array.count into local variable like count = array.count and use it.

for(i=0; i < count; i++){
alert("array data : " +array[i]);
}

  • Don't use eval() when not necessary
    • eval statement is expensive in terms of performance
    • eval parameters are executed dynamically. So it's hard to understand the program and the program is not more reliable.
  • Don't wrap try/catch within loops. - Every catch statement, javascript creates dynamically scope.
  • Don't pass function as a string to setTimeout() - setTimeout("myFunction()","") - Internally this will use eval statement instead use function reference like setTimeout(myFunction,....).
  • Don't use symbol + for concatenating strings, use String.concat() or Array.join
  • Don't use function constructor like new Function() -  as equal to eval method.
  • Don't use "with" statement. - Used to define the new scope of the element. It is more expensive to look up variables in other scope.

with(document.getElementById("divid").style){
color = '#fff';
width = '150px';
backgroundcolor ='#000′;
}

Javascript has better alternatives for this.

var divobj = document.getElementById("divid");
divobj.style.color = '#fff';
divobj.style.width = '150px';
divobj.style.backgroundcolor = '#000′;

  • Cache offsetHeight/offsetWidth before using computation - Every time there is an internal re-flow happening

Re-flow happens at Initial page load, Browser window resize, Layout style changes, Add/Remove DOM nodes.

  • Use innerHTML to insert the element into the node
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