Does the JavaScript script within the 3.script tag execute when the page loads?will be executed. JavaScript scripts defined within the HTML page and external scripts specified by the SRC attribute are executed. Because the JavaScript code on an HTML page is part of an HTML document, the order in which JavaScript is executed when the page is loaded is the order in which the markup is introduced <script>
, which executes first. such as the following HTML and JS script files.
JS script file:
alert("已加载3");function load1(){ alert("已加载4");}
HTML file:
<! DOCTYPE html><html><head><meta charset="Utf-8" /><script type="Text/javascript">Alert ("page loaded 1! "); function load(){ alert ("page loaded 2"); }</script><script type="text/javascript" src="Test.js"></script></head><body onload="Load ()"> <H1>Hello world!</H1></body></html><script type="Text/javascript">Alert ("page loaded 5! ");</script>
Open the HTML file in a browser, and then pop up: "Page loaded 1!" "," Loaded 3! "," Page loaded 5! "and" Page Loaded 2 ". The body's OnLoad event will not be triggered until the entire HTML file is loaded.
* * Note: The named function of **javascript (that is, a function with a name) is not executed when the page is loaded, and must be displayed before the call is executed. The onload event of the body above shows the call function load ().
Can global variables and functions defined by 4.Javascript scripts be called across a script tag?Both global variables and functions can be called across a script tag.
But the difference between global variables and functions is that for global variables, whether they are in the same script or a different script, they must be defined before they are used. But for functions, the same script can be used first, then defined.
<! DOCTYPE html><html> <head> <meta charset="Utf-8"/> <script> var tmp=9; </script> </head> <body> </body> <script>_alert (TMP); //Call function function _alert(var1){ alert (var1); } _alert (TMP1); //Call function, popup undefined var tmp1=8; </script> </html>
What is the difference between null and "" Empty strings in 5.js?In essence, NULL is an empty object, and its type is object. Alert (typeof (null)); Will output object;
"" is an empty string, alert (typeof ("")), and a string is output.
Using the difference, null can empty an object of any type, turning the object's type into object.
<script> var str="lvlv"; str=null; alert(str); alert(typeof(str)); //输出"object"</script>
Eject separately: null and object.
What is the difference between null and undefined in 6.javascript?Tell the difference between null and undefined before you describe what data types are in JS.
JS has 7 Big data types in W3cschool, namely: Undefined, Null, Boolean, number, String,array, and object.
However, it is important to note that there are no undefined and null keywords in JS. Undefined is a value of type undefined, and the undefined type is only undefined this value. Null is a value of the null type, and the null type has only one private value, NULL, which is its literal. Both null and undefined are values, not objects.
Why the TypeOf operator returns "Object" for null values. This is actually an error in the initial implementation of JavaScript, and is then used by ECMAScript.
There is also a need to note that:
The value undefined is actually derived from the value null, so ECMAScript defines them as equal.
alert(nullundefined); //输出 "true"
So the difference between null and undefined is that NULL is a null-type value, and undefined is a value of type undefined.
A typeof operator is posted here to evaluate the return value of variables of various types:
The difference between 7.ECMAScript and JavaScriptECMAScript is a script programming language that is standardized by the ECMA International (formerly the European Association of Computer manufacturers, the English name is European Computer Manufacturers Association) through ECMA-262.
ECMAScript is a core part of JavaScript, ECMAScript describes the syntax and basic objects of JavaScript;
In addition, the components of JavaScript include:
The DOM describes the methods and interfaces for handling Web page content;
The BOM describes the methods and interfaces that interact with the browser.
In other words, although ECMAScript is an important standard, it is not the only part of JavaScript, and of course, it is not the only one that is standardized. In fact, a complete JavaScript implementation is made up of the following 3 different parts:
Core (ECMAScript);
Document Object Model (DOM);
The browser object model (BOM).
The diagram is part of javascript:
8.JavaScript How to define a classJavaScript itself does not support object-oriented, it does not have an access control, it does not define the class's keyword class, it does not support inherited extend or colons, it does not support polymorphic virtual functions and virtual keywords. However, JavaScript is a flexible language, so let's look at how JavaScript without the keyword class implements the class definition and creates the object.
How to define classes in JavaScript, create objects for classes, create public and private properties and methods, create static properties and methods, simulate constructors, and discuss error-prone this. Refer to: Defining classes in JavaScript. This article is well written and understandable, and is worth reading.
Can a method in 9.JavaScript have a return value?The method in JS can have a return value. Because JS is a weakly typed language, you do not need to indicate the return value type for the method display, and return the return value directly using return, for example:
function add(a, b){ return a + b;}alert(add(1, 2));//3
If return is not written in the function, the function returns undefined and can be judged as to whether there is a return value.
What are the different representations of 10.html colors?There are three main types,
The first type: RGB mode.
There are two ways to express it:
(1) Hexadecimal representation. such as red: #ff0000, Green: #00ff00, Blue: #0000ff. Note that hexadecimal is case-insensitive;
(2) Decimal or Percent form: red: rgb (255,0,255) or RGB (100%,0%,0%). Note RGB case is available;
If the alpha opacity is increased, the representation is as follows:
Red: Rgba (255,0,255,1) or Rgba (100%,0%,0%,1). The value range for Alpha opacity is 0 to 1 or it cannot be expressed as a percentage.
The second type: HSL mode.
This is the new color notation for CSS3. The HSL color model is also a color standard for industry, which corresponds to Hue (hue), also known as hue, saturation (saturation), lightness (lightness).
The values for each of the three are:
Hue (hue). 0 (or 360) indicates red, 120 is green, 240 is blue, and other values are preferred to specify the color. The value is: 0-360;
Saturation (saturation). The values are: 0%-100%;
Lightness (brightness). Values are: 0%-100%.
For example, Red is indicated as: HSL (0,%100,%50). If the brightness is 100%, then it becomes white. HSL is case insensitive.
If Alpha opacity is added, red can be represented as Hsla (0,%100,%50,1).
the third type: HTLM the predefined color names.
Use HTLM predefined color names, such as Red,blue,green.
Reference documents[1] In the body write JavaScript will automatically execute?
[2]js load execution order in HTML
[3] Where should the JavaScript code be placed in the HTML code better?
[4]http://www.w3school.com.cn/js/pro_js_primitivetypes.asp
[5] JavaScript implementation
[6] Defining classes in JavaScript
[7]HSL Color
Web front-end development Beginners Ten Questions Collection (1)