JavaScript常见基础问题汇总

  1. javascript中not defined、undefined、null以及NaN的区别

    not defined:使用未定义的变量运算,程序会报错;undefined:变量未赋值(没有被初始化)或对象成员不存在;null:空对象(常用来表示函数企图返回一个不存在的对象),undefined是派生自null,所以有undefined==null;NaN:Not a Number,当运算无法返回正确的数值时,就会返回NaN值。具体可参考该文章

  2. if语句求值是调用什么函数

    eval()函数可计算某个字符串,并执行其中的的 JavaScript 代码。具体参考该文章

  3. javascript中怎样创建private方法,有什么缺点

var Employee = function (name, company, salary) {
     
    this.name = name || "";       
    this.company = company || ""; 
    this.salary = salary || 5000; 

    // Private method
    var increaseSalary = function () {
     
        this.salary = this.salary + 1000;
    };

    // Public method
    this.dispalyIncreasedSalary = function() {
     
        increaseSlary();
        console.log(this.salary);
    };
};

// Create Employee class object
var emp1 = new Employee("John","Pluto",3000);
// Create Employee class object
var emp2 = new Employee("Merry","Pluto",2000);
// Create Employee class object
var emp3 = new Employee("Ren","Pluto",2500);

javascript创建私有方法很消耗内存,尽量不要使用

  1. 未完待续

你可能感兴趣的:(前端(js,javascript,基础,面试问题)