JavaScript (1)

JavaScript is the most popular scripting language on the internet, used in HTML and the web, and in a wide range of devices such as servers, PCs, laptops, tablets, and smartphones.
HTML defines the content of a web page
CSS describes the layout of a web page
JavaScript The behavior of a web page
JavaScript can change most properties of any HTML element
isNaN(x) is true if not a number
JavaScript is the default scripting language in all modern browsers as well as in HTML5.
JavaScript doesn't have any functions for printing or outputting.
In browsers (Chrome, IE, Firefox) use F12 to enable debug mode
123e5==12300000
JavaScript identifiers must start with a letter, an underscore (_), or a dollar sign ($).

Here are the most important reserved words in JavaScript:
abstract else instanceof super
boolean enum int switch
break export interface synchronized
byte extends let this
case false long throw
catch final native throws
char finally new transient
class float null true
const for package try
continue function private typeof
debugger goto protected var
default if public void
delete implements return volatile
do import short while
double in static with

In JavaScript, camel case naming rules are common, such as lastName (instead of lastname).

JavaScript statement identifier (keyword):
statement description
break is used to break out of the loop.
The catch statement block executes the catch statement block when an error occurs in the execution of the try statement block.
continue skips an iteration in the loop.
do ... while executes a block of statements, continuing to execute the block while the conditional statement is true.
for executes a block of code a specified number of times while the conditional statement is true.
for ... in is used to traverse the properties of arrays or objects (loop operations on the properties of arrays or objects).
function defines a function
if ... else to perform different actions based on different conditions.
The return exit function
switch is used to perform different actions based on different conditions.
throw throws (generates) an error.
try implements error handling and is used together with catch.
var declares a variable.
while A block of statements is executed when the conditional statement is true.
Backslash wraps lines of code
JavaScript data types [String, Number, Boolean, Array, Object, Null, Undefined. ] A variable can be emptied by setting its value to null.
A JavaScript object is data that has properties and methods.
There are two ways to access object properties: person.lastName; person["lastName"];

**Object method:
Note: <script>
var person = {
    firstName: "John",
    lastName : "Doe",
    id : 5566,
    fullName : function() {
       return this.firstName + " " + this.lastName;
    }
};
document.getElementById("demo").innerHTML = person.fullName();
</script>
A function is a reusable block of code that is event-driven or executed when it is called.
The lifetime of JavaScript variables starts from the time they are declared.
Local variables are deleted after the function runs.
Global variables are deleted when the page is closed.
In JavaScript, objects and functions are also variables.
In JavaScript, a scope is a collection of accessible variables, objects, and functions.
JavaScript function scope: The scope is modified within the function.
A string can be any character inserted between quotes. You can use single quotes or double quotes:
you can use quotes inside strings, the quotes inside strings are not the same as the quotes inside strings: the
escape character (\) can be used to escape apostrophes, newlines, quotes, etc. other special characters.
var x = "John"; // x is a string
var y = new String("John"); // y is an object
=== absolutely equal (both value and type are equal)
!== absolutely not equal (value and types are not equal)
JavaScript supports different types of loops:
for - loops a block of code a certain number of times
for/in - loops through the properties of an object
while - loops a specified block of code while a specified condition is true
do/while - also while loop while the specified condition is true The specified code block
continue statement (with or without label references) can only be used in a loop.
The break statement (without a label reference), can only be used in a loop or switch.
Referenced by tags, the break statement can be used to break out of any block of JavaScript code:
Note: <script>
function myFunction()
{
var x;
var txt="";
var person={fname:"Bill",lname:"Gates",age :56}; 
for (x in person)
{
txt=txt + person[x];
}

document.getElementById("demo").innerHTML=txt;
}
</script>
 typeof operator to check the data type of the variable.
There are 5 different data types in JavaScript:
string
number
boolean
object
function
3 object types:
Object
Date
Array
2 data types that do not contain any value:
null
undefined
Please note:
The data type of NaN is number The
data type of Array (Array) is object
The data type of Date (Date) is object The
data type of null is object
The data type of undefined variable is undefined

***constructor attribute returns all Constructor for JavaScript variables.
 constructor property to see if the object is an array (contains the string "Array"):
 function isArray(myArray) {
    return myArray.constructor.toString().indexOf("Array") > -1;
}
 constructor property to see if it is an object Whether it is a date (contains the string "Date"):
function isDate(myDate) {
    return myDate.constructor.toString().indexOf("Date") > -1;
}
 Number() can convert a string to a number, parsing Strings become numbers; booleans can be converted to numbers
Operator + can be used to convert variables to numbers:
When JavaScript tries to manipulate a "wrong" data type, it automatically converts to the "correct" data type.
In JavaScript, regular expressions are commonly used with two string methods: search() and replace().
The search() method is used to retrieve a specified substring in a string, or a substring matching a regular expression, and

returns starting position of the substring.
The replace() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression
var str = "Visit w3cschool";
var n = str.search(/w3cschool/i); or var n = str. search("w3cschool"); n=6.
i performs a case-insensitive match.
g performs a global match (finds all matches instead of stopping at the first match found).
m performs a multiline match.
The test() method is a regular expression method.
The test() method is used to detect whether a string matches a pattern, and returns true if the string contains matching text, otherwise returns false.
The exec() method is used to retrieve matches of a regular expression in a string.
The function returns an array in which the matching results are stored. If no match is found, the return value is null.

The try statement tests a block of code for errors.
The catch statement handles errors.
throw statement to create custom errors.
<a href="javascript:void(0)">Click here and nothing happens</a>
<a href="javascript:void(alert('Warning!!!'))">Click me! </a>
The difference between href="#" and href="javascript:void(0)"
# contains a location information, the default anchor is #top which is the top of the web page.
And javascript:void(0), just means a dead link.
When the page is very long, # will be used to locate the specific location of the page, the format is: # + id.

Guess you like

Origin blog.csdn.net/Decadent_2014/article/details/46911095