牛客網刷題(三)
1、以下のコード実行後、consoleの出力は?function Foo(){ console.log(this.location); } Foo();
現在のウィンドウのLocationオブジェクトundefined null Type Error
A JavaScriptのthis原理http://www.ruanyifeng.com/blog/2018/06/javascript-this.html
2、
3、次のブロック内宣言関数のやり方はどれが正しいですか?if(x){function foo(){}}if(x){var foo=function(){}}if(x){foo=function(){}}ECMAScriptはブロック内関数を明確に規範化し,javascriptはこの規範を実現した.
正解:B
解析:
4、配列属性length、方法:concat/sort/reverseなど
5、css新特性:datetime_local(時間変更可能)https://www.w3school.com.cn/jsref/dom_obj_datetime-local.asp
6、次のコードを読んで正しい()var b=3を出力します.(function(){ b = 5; var b = 2; })(); console.log(b);
5 3 2プログラムエラー
答え:B
解析:直ちに関数内部を実行し、**varは変数の昇格が発生し、**結果は(function(){var b;b=5;b=2;})に相当する.()したがって、この即時実行関数は、グローバル環境におけるbを変更しないので、グローバル環境におけるbは依然として3である.
即時実行関数
即時実行関数の役割:関数の名前を付ける必要はありません.グローバル変数を汚染することを回避します.直ちに実行関数の内部に個別の役割ドメインが形成され、外部で読めないプライベート変数をカプセル化することができます.
7、以下の式の結果がtrue()正解:A C Dあなたの答え:D(エラー)undefined==null isNaN("100")parseInt("1 a")==1[]instanceof Array
ACD
NaN属性は、数値以外の値を表す特殊な値です.このプロパティは、値が数値ではないことを示します.Numberオブジェクトをこの値に設定して、数値値ではないことを示すことができます.
8、thisオブジェクトに対する理解の下でどれが正しいか()thisは常に関数の直接呼び出し者(間接呼び出し者ではない)を指します.newキーワードがある場合、thisはnewから出てきたオブジェクトを指します.イベントでは、thisは常にこのイベントをトリガーしたオブジェクトを指します.thisは関数の実行時に自動的に生成された内部オブジェクトで、関数の内部でしか使用できません.
正解:A B D
イベントでは、thisはこのイベントをトリガーするオブジェクトを指し、特に、IEのattachEventのthisは常にグローバルオブジェクトWindowを指す.
現在のウィンドウのLocationオブジェクトundefined null Type Error
A JavaScriptのthis原理http://www.ruanyifeng.com/blog/2018/06/javascript-this.html
2、
3、次のブロック内宣言関数のやり方はどれが正しいですか?if(x){function foo(){}}if(x){var foo=function(){}}if(x){foo=function(){}}ECMAScriptはブロック内関数を明確に規範化し,javascriptはこの規範を実現した.
正解:B
解析:
4、配列属性length、方法:concat/sort/reverseなど
5、css新特性:datetime_local(時間変更可能)https://www.w3school.com.cn/jsref/dom_obj_datetime-local.asp
<!DOCTYPE html>
<html>
<body>
<h3> Local Datetime </h3>
<input type="datetime-local" id="myLocalDate" value="2014-06-01T10:55:33">
<p> datetime 。</p>
<button onclick="myFunction()"> </button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myLocalDate").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
6、次のコードを読んで正しい()var b=3を出力します.(function(){ b = 5; var b = 2; })(); console.log(b);
5 3 2プログラムエラー
答え:B
解析:直ちに関数内部を実行し、**varは変数の昇格が発生し、**結果は(function(){var b;b=5;b=2;})に相当する.()したがって、この即時実行関数は、グローバル環境におけるbを変更しないので、グローバル環境におけるbは依然として3である.
即時実行関数
即時実行関数の役割:関数の名前を付ける必要はありません.グローバル変数を汚染することを回避します.直ちに実行関数の内部に個別の役割ドメインが形成され、外部で読めないプライベート変数をカプセル化することができます.
7、以下の式の結果がtrue()正解:A C Dあなたの答え:D(エラー)undefined==null isNaN("100")parseInt("1 a")==1[]instanceof Array
ACD
// 1. isNaN() NaN;
// NaN NaN true
console.log(isNaN('e'));//true, e NaN
console.log(isNaN('11'));//false, , NaN
console.log(isNaN(null));//false, null 0, NaN
console.log(isNaN(NaN));// true,NaN true
// 2. parseInt(string,raix)
// 2.1 :string
console.log(parseInt('223'));//223
// 2.2 ,
console.log(parseInt('22e3'));//22
// 2.3 , NaN
console.log(parseInt('e21'));//NaN
// parseInt() , , parseInt() ?
// 2.4 parseInt() , 2 36 , NaN
console.log(parseInt(1,1));//NaN , 1 1 <2,
console.log(parseInt(1,2));//1, =2,
// 2.5 , 10
console.log(parseInt(99));//99
// 2.6 0
console.log(parseInt(99,0));//99
// 2.7 0x/0X 16
console.log(parseInt(0x99));//153=16*9+9
console.log(parseInt(0x99,10));// 0x ,
// 2.8 ,
var arr=[1,2,3,2,5];
console.log(arr.map(parseInt));//[1, NaN, NaN, 2, NaN]
// arr.map arr ,
// map *** ,
parseInt(1,0);//1, 0
parseInt(2,1);//1 <2, !
parseInt(3,2);// 2 , 3 0——2 (3 11), 2
parseInt(2,3);// , 0-3, 2
parseInt(5,4);//4 5, NaN
NaN属性は、数値以外の値を表す特殊な値です.このプロパティは、値が数値ではないことを示します.Numberオブジェクトをこの値に設定して、数値値ではないことを示すことができます.
8、thisオブジェクトに対する理解の下でどれが正しいか()thisは常に関数の直接呼び出し者(間接呼び出し者ではない)を指します.newキーワードがある場合、thisはnewから出てきたオブジェクトを指します.イベントでは、thisは常にこのイベントをトリガーしたオブジェクトを指します.thisは関数の実行時に自動的に生成された内部オブジェクトで、関数の内部でしか使用できません.
正解:A B D
イベントでは、thisはこのイベントをトリガーするオブジェクトを指し、特に、IEのattachEventのthisは常にグローバルオブジェクトWindowを指す.