Dark Horse Programmer JavaScript Video Resource Sharing
Dark Horse Programmer JavaScript Video Tutorial" will introduce you to JavaScript in detail. JavaScript is a literal scripting language and a scripting language widely used in client-side Web development. Currently used by millions of web pages to improve design, validate forms, detect browsers, create cookies, and more.
Video playback address: http://www.php.cn/course/500.html
The difficulty of this video is Array loop, testing logical ability. The following summarizes various loop examples:
How do we traverse the elements in the array? When JavaScript first emerged 20 years ago, you might implement array traversal like this:
var arr=["one","two","three"];2 for(var i=0;i<arr.length;i++){3 document.write(arr[i]);4 }
Since the official release of ES5, you can use the built-in forEach method to traverse the array:
myArray.forEach(function (value) { console.log(value);});实际上forEach有三个参数 分别为 值 下标 数组本身 于是我们有[].forEach(function(value, index, array) { // ...}); 对比jQuery中的$.each方法: $.each([], function(index, value, array) { // ...});
You will find that, The first and second parameters are exactly opposite. Please pay attention and don’t remember them wrongly. The same is true for similar methods later, such as $.map.
$.each(Array, function(i, value) { Array //数组 this; //this指向当前元素 i; //i表示Array当前下标 value; //value表示Array当前元素}); var arr = [ "one", "two", "three", "four"]; $.each(arr, function(){ alert(this); }); //上面这个each输出的结果分别为:one,two,three,four var obj = { one:1, two:2, three:3, four:4}; $.each(obj, function(key, val) { alert(obj[key]); }); //这个each就有更厉害了,能循环每一个属性 //输出结果为:1 2 3 4
For example:
arr.forEach(function(i,j,v){ document.write("<br />数组的值"+i+ "<br />数组的下标"+j+","+ "<br />数组本身"+v+"---") })
This code looks more concise, but this method also has a small flaw:
forEach is not flexible enough
arr.forEach is not easy to use. You cannot use the break statement to interrupt the loop, nor can you use the return statement to return to the outer function.
Of course, it would also be great if you only use the for loop syntax to traverse the array elements.
Then, you must want to try a for-in loop:
for (var index in myArray) { // 千万别这样做 console.log(myArray[index]); }
In this code, the value assigned to index is not an actual number, but the string "0", " 1", "2", it is very likely that string arithmetic calculations are performed unintentionally, for example: "2" + 1 == "21", which brings great inconvenience to the encoding process.
In short,
for-in is designed for ordinary objects. You can traverse to get string type keys, so it is not suitable for array traversal.
for...in is not suitable for traversing arrays
for...in will traverse custom properties or even prototype properties. The index is a string instead of a numerical value. In some cases, it is not even possible. Sequential iteration
Powerful for-of loop
ES6 will not break the JS code you have written. It seems that thousands of web sites currently rely on for-in loops, and some of them even use them for array traversal. Adding array traversal support by fixing for-in loops would make this even more confusing, so the standards committee added a new loop syntax in ES6 to solve the current problem.
We need a more convenient way to traverse the array, as simple and easy to use as using for...in to traverse the object, that is for...of
is like Like this:
for (var value of myArray) { console.log(value); }
Yes, does this loop look familiar compared to the previous built-in methods? Well, we are going to explore what powerful functions are hidden under the appearance of the for-of loop. For now, just remember:
This is the most concise and direct syntax for traversing array elements
This method avoids all the pitfalls of for-in loops
Unlike forEach(), it can correctly respond to break, continue and return statements
The for-in loop is used to traverse object properties.
The for-of loop is used to iterate over data—such as values in an array.
But, it’s not just that!
The for-of loop can also traverse other collections
The for-of loop not only supports arrays, but also supports most array-like objects, such as DOM NodeList objects.
The for-of loop also supports string traversal, which treats the string as a series of Unicode characters to traverse:
for (var value of myArray) { console.log(value); }
It also supports Map and Set object traversal.
$.map(array,function)
Syntax analysis: For each element in the array, call the function function for processing, and then return the result to get a new array.
Explanation by example: Return each element in the array by *2 and return a new array. The code is as follows
<html> <head> <script type="text/javascript" src="jquery-1.8.2.min.js"></script> <script type="text/javascript"> var arr = [2,3,6]; var arr2 = $.map(arr,function(item){return item*2;}); for(var i=0,len=arr2.length;i<len;i++){ document.write(arr2[i]+"<br />");//结果为 4 6 12 } </script> </head> </html>
Additional explanation: item represents each element. This is a formal parameter and can be replaced by others.
The teacher in this video explains things in a simple and easy-to-understand way, with clear organization, layer-by-layer analysis, interlocking links, rigorous argumentation, and rigorous structure. He uses the logical power of thinking to attract students' attention, and uses reason to control the classroom teaching process. The teaching skills are full of wit. Various teaching methods and techniques are readily available and can be used freely and appropriately without any trace of polishing.
The above is the detailed content of Dark Horse Programmer JavaScript Video Resource Sharing. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software