JavaScript study notes record my journey_Basic knowledge
1. What is JavaScript?
(1) HTML is just a markup language that describes the appearance of a web page. It does not have the ability to calculate or judge. If all calculations and judgments are made (such as judging whether the text box is empty, judging whether two passwords have been entered) Consistent) If the store executes it on the server side, the web page will be very slow, difficult to use, and put a lot of pressure on the server. Therefore, it is required to perform some simple operations in the browser. To judge, JavaScript is a A language that executes on the browser side.
(2) JavaScript and Java have no direct relationship. The only relationship is that JavaScript was originally called LiveScript. Later, it absorbed some features of Java and was upgraded to JavaScript. JavaScript is sometimes referred to as JS.
(3) JavaScript is an interpreted language and can be executed at any time without compilation. In this way, even if there are grammatical errors, the parts without grammatical errors can still be executed correctly.
JS development environment
(1) JavaScript and Jqery auto-complete function in VS.
(2) JS is a very flexible dynamic language, not as rigorous as static languages such as C#.
JS Getting Started
(1)
< ;script type="text/javascript">
alert(new Date().toLocaleDateString());
(2) JavaScript code is placed in In the <script> tag, <script> can be placed at any position such as <head>, <body>, and there can be more than one <script> tag. The alert function is a pop-up message window, and new Date() is to create an object of Date class, and the default value is the current time. <br>(3) The <script> placed in <head> has been run before the body is loaded, and the <script> written in the body is executed one by one as the page is loaded. <br>(4) In addition to declaring JavaScript in the page, you can also write JavaScript in a separate JS file and then introduce it into the page: <script src=”common.js” type=”text/javascript ”></script>. The advantage of declaring to a separate JS file is that multiple pages can be shared, reducing network traffic.
Event
(1) Click me
I won’t pop up anything
Click me
(2) JavaScript also has the concept of events, when the button is clicked
1)
2) Only the JavaScript in the href of the hyperlink requires "JavaScript:", because it is not an event, but treats "JavaScript:' like" http:", "ftp:", "thunder://", ed2k://, mailto:// are the same network protocols and are processed by the JS parsing engine. There is only this special column in href.
JS variable
(1) You can use double quotes or single quotes to declare strings in JavaScript, mainly to facilitate integration with HTML and avoid the trouble of escape characters.
(2) var i=10. ; //Declare a variable with the name i, pointing to the integer 10. Once it points to 10, i is of type int, alert(i);
(3) There are two types of null and underfined in JavaScript, and null represents the value of the variable. If it is empty, underfined means that the variable does not point to any object and has not been initialized.
(4) JavaScript is a weak type and cannot represent variables: int i=10. Variables can only be declared through var i=10; Unlike var in C#, it is not type inference like in C#
(5) In JavaScript, you can also use var directly instead of declaring variables. Such variables are "global variables", so unless you really want to use them globally. Variable, otherwise it is best to add var when using it.
(6) JS is dynamically typed, so var i=10;i="abc" is legal.
JavaScript
(1)
var sum = 0;
for (var i = 0; i <= 100; i ) {
sum = sum i;
}
alert(sum);
(2) If the code in JavaScript has syntax If an error occurs, the browser will pop up an error message. Checking the error message can help troubleshoot the error.
(3) JavaScript debugging, using VS can easily debug JavaScript. You need to pay attention to a few points when debugging:
1) IE debugging options should be turned on, Internet Options-Advanced, remove "Disable script debugging" Check the box in front of ".
2) Run the interface in debug mode.
3) Setting breakpoints, monitoring variables and other operations are the same as C#.
Judge variable initialization
(1) Three ways to judge whether variables and parameters are initialized in JavaScript.
var r;
if (r == null) { if (typeof (r) == "undefined") { if (!x) {
alert("null"); alert ("undefined"); alert("Not 🎜>(1) Method of declaring functions in JavaScript:
The code is as follows:
Copy code
The code is as follows:
(1)
The code is as follows:
(4)
The code is as follows:
(2)
Copy code
The code is as follows:
p1 .SayHello();
(3) The class name must be declared. function Person(name,age) can be regarded as declaring the constructor. Name and Age attributes are also dynamically added by the user.
Array() object
(1) The Array object in JavaScript is an array. First of all, it is a dynamic array, and it is a super complex like arrays ArrayList, Hashtable, etc. in C#.
(2)
Copy code
The code is as follows:
(3) No need to pre-set the size, dynamic.
Array() Exercise 1
(1) Array exercise, find the maximum value in an array.
The code is as follows:
Array( ) Exercise 2
(1) Reverse the order of the elements of a string array, {3,9,5,34,54}{54,34.5.9.3}. Do not use the reverse function in JavaScript. Tip: Swap the i-th and length-i-1 to define the function.
Copy code
The code is as follows:
Dictionary usage of Array
(1 ) Array in JS is a treasure, not only an array, but also a Dictionary and a Stack.
(2)
var names = new Array( );
names["人"] = "ren";
names[" buckle"] = "kou";
names["hand"] = "shou";
alert(names ["人"]);
alert(names.人);
for (var k in names) {
alert(k);
}
( 3) Use it like Hashtable and Dictionary, and it is as efficient as them.
Simplified declaration of Array()
(1) Array can also have a simplified way
var arr=[3,4,5,6,7]; //Ordinary array initialization
This Arrays can be seen as a special case of names["人"]="ren";, that is, the keys are 0,1,2,3,4,5
(2) Simplified creation method in dictionary style
var arr={”tom”=30,”jim=”30};
Array, for and others
(1) For array-style Array, you can use the join method to concatenate it into a string.
var arr = ["tom", "jim", "kencery"];
alert(arr.join(",")); //join in JS is an array method, unlike .net which is a string method
(2 ) for loop can be used like foreach in C#.
for (var e in document) {
alert (e);
}

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
