This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>item One</li> | |
<li>item Two</li> | |
<li>item Three</li> | |
</ul> | |
<script> | |
var listElements = document.getElementsByTagName("li"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// old way | |
var myOldString = "some really long text repeated" + | |
some really long text repeated" + | |
some really long text repeated"; | |
// Potentially better for Performance and Memory usage | |
var myString = "some really long text repeated\n\ | |
some really long text repeated\n\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// old concatenation (creates a new variable in memory for each +) | |
var stuckTogetherOld = "value1" + "value2" + "value3"; | |
// Better: | |
// Front End Performance Tip for string concatenation or JS Templates | |
var stuckTogether = ["value1", "value2", "value3"].join(""); | |
// Quicker to execute | |
var tmpl = ''.concat( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="main" class="style1 style2 style3"> | |
</div> | |
<script> | |
console.log(main.className.split(" ")[0]); // first className | |
console.log(main.className.split(" ")[1]); // second className | |
console.log(main.className.split(" ")[2]); // third className |
NewerOlder