The JS object is a container for key-value pairs,
Be sure to understand the use of commas and semicolons in JS
If a variable is not declared within a function (without using the var keyword), the variable is a global variable.
/w3cschool/i is a regular expression. W3cschool is a pattern (for retrieval). I is a modifier (search is case insensitive).
Use regular expressions to search for "w3cschool" strings and are not case-sensitive:
var str = "Visit W3cschool";
var n = str.search (/w3cschool/i);
Gets the value of the specified ID
var str = document.getElementById ("Demo2"). InnerHTML;
Regular expression modifiers
Modifiers can be case insensitive in global search:
Modifier description
I perform a match on case insensitive.
G performs a global match (finds all matches rather than stops after the first match is found).
M performs multi-line matching.
<script>
var patt1=new RegExp ("E");
var patt2=new RegExp (/o/);
document.write (Patt1.test ("The best things in life is free");
document.write (Patt2.test ("The best things in life is free");
</script>
It's more fun to write.
document.write (/e/.test ("The best things in life is free");
Custom
Try
{
var X=document.getelementbyid ("Demo"). Value;
if (x== "") throw "value is null";
if (IsNaN (x)) throw "is not a number";
if (x>10) throw "too large";
if (x<5) throw "too small";
}
catch (Err)
{
var Y=document.getelementbyid ("mess");
Y.innerhtml= "Error:" + Err + ". ";
}
JSON data writing: ' {' "": [' + ' {"": "", "": "}, ' + ' {" ":" "," ":" "}]} '. Then convert the JSON data into a JS object
var stu= ' {"Student": [' +
' {' name ': ' Hanxiaoshun ', ' age ': ' 26 '}, ' +
' {' name ': ' Chen Jiabin ', ' age ': ' 26 '}]} ';
Objj=json.parse (Stu);
document.getElementById ("Demo"). InnerHTML =
Objj.student[1].name + "" + objj.student[1].age;
Click here nothing is going to happen
<body>
<a href= "javascript:void (0)" > single here Nothing will happen </a>
</body>
Object rules
Rules for object definitions:
Put the left curly brace on the same line as the class name.
There is a space between the colon and the attribute value.
Strings use double quotes, and numbers are not required.
Do not add a comma after the last property-value pair.
Place the right curly brace on one line independently and with the symbol as the ending symbol.
var person = {
FirstName: "John",
LastName: "Doe",
AGE:50,
Eyecolor: "Blue"
};
Each line of code characters is less than 80
For readability each line of characters is suggested to be less than 80.
If a JavaScript statement exceeds 80 characters, it is recommended that you wrap the operator or comma after the line.
Instance:
document.getElementById ("Demo"). InnerHTML =
"Hello Runoob.";
There are 4 types of JavaScript functions
JavaScript Learning JS objects and JSON objects (Obj=json.parse (STU))