- 下面程序的输出结果是多少?
function sum(a, b) {return a + b;}sum(1, "2");
- 下面程序的输出结果是多少?
var str = "我非常喜欢编程";str.length = 3;console.log(str);
- 下面程序的输出结果是多少?
let number = 0;console.log(number++);console.log(++number);console.log(number);
- 下面程序的输出结果是多少?
function nums(a, b) {if (a > b)console.log('a is bigger')elseconsole.log('b is bigger')return a + b}console.log(nums(4, 2))console.log(nums(1, 2))
- 下面程序输出结果是多少?
function side(arr) {arr[0] = arr[2];}function func1(a, b, c = 3) {c = 10;side(arguments);console.log(a + b + c);}function func2(a, b, c) {c = 10;side(arguments);console.log(a + b + c);}func1(1, 1, 1);func2(1, 1, 1);
- 下面代码的输出结果是什么?
var a = 3;var b = new Number(3);var c = 3;console.log(a == b);console.log(a === b);console.log(b === c);
- 执行下列语句后,a.length的值为?
var a = [];a.push(1, 2);a.shift(3, 4);a.concat([5, 6]);a.splice(0, 1, 2);
- 下面这几段代码分别输出结果是多少?为什么?
var a = {}, b = '123', c = 123;a[b] = 'b';a[c] = 'c';console.log(a[b]);// example 2var a = {}, b = Symbol('123'), c = Symbol('123');a[b] = 'b';a[c] = 'c';console.log(a[b]);// example 3var a = {}, b = {key:'123'}, c = {key:'456'};a[b] = 'b';a[c] = 'c';console.log(a[b]);
- 下面每项的返回值是什么?为什么?
null == undefined0.1 + 0.2 == 0.3typeof NaNtypeof Functiontypeof Objecttypeof {}'a' + 1'a' - 1Function instanceof ObjectObject instanceof Function
- 下面程序的输出结果是多少?
var array = []for(var i = 0; i < 3; i++) {array.push(() => i)}var newArray = array.map(el => el())console.log(newArray)
- 下面程序的输出结果是多少?
function a(m, n) {var b = function (l) {return l <= m ? l * b(l + 1) : 1;}return b(m - n + 1);}console.log(a(4, 2));
- 下面程序的输出结果是多少?
console.log(typeof undefined == typeof NULL);console.log(typeof function () {} == typeof class {});
- 执行后a和b.age的值分别为
var a = 10var b = {age: 11}function fn(x,y) {--y.age;return --x;}fn(a,b)
- 下面程序的执行结果是:
var number = 4;var numberFactorial = (function (number){return (number === 0)? 1: number* factorial(number-1)})(number)console.log(numberFactorial)
- 下面程序的输出结果是:
var array = []for(var i = 0; i < 3; i++) {array.push(() => i)}var newArray = array.map(el => el())console.log(newArray)
- 下面程序的输出结果是:
function addToList(item, list) {return list.push(item)}const result = addToList("nowcoder", ["hello"])console.log(result)
- 下面程序的输出结果是:
const first = () => { console.log('first'); return false; }const second = () => { console.log('second'); return true; }console.log( first() && second() );console.log( second() || first() );
- 下面代码的输出结果是:
var s='12ab3cd', arr=s.split(/d/);console.log(arr[3],arr[4])
- 下面程序的输出结果是:
function getAge(...args) {console.log(typeof args);}getAge(21);
- 下面程序的输出结果是:
var arr=[1,2,3];arr.push(arr.shift())console.log(arr[1],arr[2])
JS深入this指向题目解析:this指向题目解析及扩展[3]关于this还可以看看:可能是最好的 this 解析了...
- 下列程序的输出结果是多少?为什么?
var x = 1;var obj = {x: 3,fun:function () {var x = 5;return this.x;}};var fun = obj.fun;console.log( obj.fun(), fun() );