7 JS basic knowledge summary

  • 2020-03-30 02:16:38
  • OfStack

1. How to add properties to an object?
Method 1: var b = {};
B/" name "=" test ";
Delete b.ame deletes the properties of the object
Method 2: b.ame ="test";
2. How to determine whether a variable is declared or not?
Typeof (a) = = "undefined"
Typeof (d) == whether "function" is a function

3. How is it represented as a string?
Through double quotes (""), single line (""), backslash (//)
    "1 + 1 = 11.
    1 + '1' = 11
There is only one number type in Javascript, and that is number.
5. Basic data types for Javascript?
Number, string, Boolean, undefined, Null
Also: Object

6. What is the difference between a class and an object? How do I implement this in javascript?


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.


Related articles: