1. How to add attributes to an object?
Method 1: var b = {};
b["name"] = "test";
delete b.name deletes 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, and that is number.
5.What are the basic data types of Javascript?
number (number), string (string), Boolean (Boolean), undefined (undefined), Null (empty)
Also: Object
6. What is the difference between classes and objects? How to implement it with javascript?
Copy the code code as follows:
function myClass()
{ }
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();
7. How many different types of loops are there in JavaScript?
Two kinds. for loop and while loop.