In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Javascript foundation of what are the ten important issues, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
1. What is Javascript?
Javascript is a programming language for Web development. JavaScript runs on the client side of the network.
According to MDN,JavaScript (usually abbreviated as JS) is a lightweight, interpretive, object-oriented language with first-class functionality, and the most famous is the scripting language for Web pages, but it is also used in many non-browser environments. It is a prototype-based multi-paradigm scripting language that is dynamic and supports object-oriented, imperative, and functional programming styles.
two。 What is DOM?
DOM represents the document object model. After the web page is loaded, the browser creates a DOM using the HTML and CSS files. DOM is represented by nodes and elements. You can use javascript to process DOM. It is a tree-like structure.
3. How to execute JS code
The question to answer is a little big. But we can say it briefly. Javascript runs on the browser. Almost every browser has a JavaScript engine. V8 is one of the most popular. Chrome uses a V8 engine. Firefox, on the other hand, uses the Spider-Monkey engine.
4. The difference between = and = =
If I put it so simply, I just check to see if the two values are the same. It does not check the types of these values. View the following code:
If (2 minutes = "2") {console.log ("true")} else {console.log ("false")}
The above code will be recorded as true. Because it treats 2 and "2" as equal, because it does not check the type.
Instead, check both type and quality. For example:
If (2 minutes = "2") {console.log ("true")} else {console.log ("false")}
This will be recorded as false. Because the values of 2 and "2" are equal, but their types are different.
5.Null (null) and Undefined (undefined)
Typically, null represents null values and values that do not exist, while undefined represents values that have been declared but not yet defined. Although you can also explicitly set undefined as a variable.
Var n console.log (typeof (n)); / / undefinedvar n = null;console.log (typeof (n)); / / object
Interestingly, the object type in JS is null.
6. Var vs Let vs Const
Before ES6, var was the only way to declare variables. But now we have more options.
There is a term for scope. A range is where these variables can be used. The var declaration is global-scoped or functional / local-scoped.
You can suspend Var, which we'll discuss in a few seconds. However, it is now preferable for let to declare variables. You can use const when you don't need to change variables later in your code. To get the difference between the two, you can read the following article, which I think is very useful.
7. Variable promotion (Hoisting)
In javascript, you can use variables before declaring them. The concept of variables and function declarations that are physically moved up to the top of the code is called variable promotion.
Console.log (num); / / Returns undefined, as only declaration was hoisted, no initialization has happened at this stagevar num; / / Declarationnum = 6
So, will the let and const variables not be suspended? The answer is much more complicated. All declarations (functions, var,let,const, and class) are suspended in JavaScript, while var declarations are initialized with undefined, but let and const declarations remain uninitialized.
8. Global variables and local variables
In javascript, scope is divided into two ways. Global and local.
A variable declared in a function is called a local scope. The variable cannot be accessed outside the function. In contrast, variables declared outside the function are called global scope. It can be accessed inside the function.
Var genre= "superhero" / / global scope// code here can't use superhero but genrefunction myFunction () {var superhero = "Batman"; / / local scope// code here CAN use superhero and genre} 9. Closure (Closure)
Closures allow us to access the scope of an external function from an internal function. You can create it by returning from one function to another. It creates a closed environment for each instance. For example:
Function sum (x) {return function (y) {return x + y;} var add5 = sum (5); var add10 = sum (10); console.log (add5 (6)); / / 11console.log (add10 (6)); / / 16
Add5 and add10 here are both closures. They share the same definition, but store different environments.
10. Callback function
According to MDN, a callback function is a function that is passed as an argument to another function, and then called inside the external function to complete some routine or operation. For example
Function greeting (name) {console.log ('Hello' + name);} function greetEmployee (name,callback) {callback (name);} greetEmployee ("Dwight", greeting)
Here, the greeting function has been used inside the greetEmployee function. This is what we call a callback function.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.