Home > Article > Web Front-end > JavaScript is not basic basic knowledge
Javascript is a very free language. In JS, everything in it is a variable. Including functions.
Function
(Definition) (Parameter 1[, Parameter 2..]) The following code will create a function and execute it.
(function (str){alert(str.length);})('test_str');
(function (str1,str2) {alert(str1 str2);})('str1111','str2222');
The first field below (the field is separated by spaces) is one of the attributes of window.location, followed by its value.
hash #ddd
host vc.wz:80
hostname vc.wz
href http://vc.wz/l.html?q=5
In Javascript , there are two ways to use regular expressions. One is to create an instance of a regular expression, but to use the regular expression-related methods in the String object.
var my_regex=/[a-z] /g;
var my_regex =new ("[a-z] ","g");
exec(string), regularizes the string and returns the matching result.
test(string), tests whether the string Contains matching results
[Edit Regular in string object] Regular in string object
match(pattern) performs regular matching based on pattern. If matched, returns the matching result, such as matching If not, return null.
search(pattern) Perform regular matching based on pattern. If a result is matched, return its index number; otherwise return -1.
replace(pattern, replacement) Perform regular matching based on pattern. Replace the matching result with replacement
split(pattern) Perform regular splitting according to pattern and return a split array
For more related tutorials, please visit JavaScript video tutorial