Home > Article > Web Front-end > Summary of 7 basic JS knowledge_Basic knowledge
1. How to add attributes to an object?
Method 1: var b = {};
b["name"] = "test";
delete b.name Delete the attributes of the object
Method 2: b.name = "test";
2. How to determine whether a variable is declared?
typeof(a) == "undefined"
typeof(d) == "function" whether it is a function
3. How to express it as a string?
By double quotes (""), single line number (''), backslash (//)
1 "1"= 11
1 '1'=11
4.Javascript has only one number type, that is number.
5.What are the basic data types of Javascript?
number (number), string (string), Boolean (Boolean), undefined (undefined), Null (empty)
In addition: Object (object)
6. What is the difference between classes and objects? How to implement it with javascript?
myClass.prototype.ID = 1;
myClass.prototype.Name = "johnson";
myClass.prototype.showMessage = function()
{
alert("ID: " this .ID "Name: " this.Name);
}
var obj1 = new myClass();
obj1.showMessage();