JavaScript ??????β???????????
?????Vampire-blog ???????[ 2017/3/22 10:36:15 ] ?????????????? Javascript
????JavaScript ??????β???????????????????
???????????????2??????????????????÷??
????1????????δ???????????? ??
????var arr = [2??3??4??5??6];
????var sum =0;
????for(var i=1;i < arr.length;i++) {
????sum +=arr[i] }
????console.log(sum);
????A??20 B??18 C??14 D??12
????2?????1??? Array ????????????????????? ??
????A???????????????????????? sort ?????????????Ч????????????? sort ????????????????????
????B??reverse ?????????????????????
????C??????????λ?ü???????????????? pop ????
????D??unshift ?????????????????????????
????3?????′??????е????????( )
????var a = b = 10;
????(function(){
????var a=b=20
????})();
????console.log(b);
????A??10 B??20 C?????? D??undefined
????4?????′??????к?????????( )
????var a=[1?? 2?? 3];
????console.log(a.join());
????A??123 B??1??2??3 C??1 2 3 D??[1??2??3]
????5???? JS ?У?’1555’+3 ?????н????( )
????A??1558 B??1552 C??15553 D??1553
????6?????′??????к?????????( )
????var a = 888;
????++a;
????alert(a++);
????A??888 B??889 C??890 D??891
????7?????????????????????????????????? ??
????A??????????????д??Сд?????????????_???????????$??
????B?????????????????????????????????????????
????C????????????????????
????D?????????????
????E???????Сд
????8?????е????????????????????? ??
????A??!(3<=1)
????B??(4>=4)&&(5<=2)
????C??(“a”==“a”)&&(“c”!=“d”)
????D??(2<3)||(3<2)
????9?????????k?????н????? ??
????var i = 0??j = 0;
????for(;i<10??j<6;i++??j++){
????k = i + j;
????}
????A??16 B??10 C??6 D??12
????10??var x = 1; function fn(n){n = n+1}; y = fn(x); y ?????? ??
????A??2 B??1 C??3 D??undefined
????11??[1??2??3??4].join('0').split('') ????н????? ??
????A??'1??2??3??4'
????B??[1??2??3??4]
????C??[“1”??“0”??“2”??“0”??“3”??“0”??“4”]
????D??'1??0??2??0??3??0??4'
????12?????????????н?????????ε??? ??????ε??? ??
????function fn1() {
????alert(1);
????}
????alert( fn1() );
????A??1
????B??alert(1);
????C??function fn1() { alert(1); }
????D??undefined
????13?????′??????к??????? ??
????fn1();
????var fn1 = function(a){ alert(a); }
????A??1 B???????? C??alert(1); D??undefined
????14??var n = "miao wei ke tang".indexOf("wei"??6)??n???????? ??
????A??-1 B??5 C???????? D??-10
????15??????? substring() ?????????????????? ??
????A???????????????????????????????????????λ????????????????????
????B??????????????????????С?????????С????λ?á?
????C????????????????????????????????????λ?á?
????D???????????ò??????????????????????
????16??alert( "12">"9" ) ?????н?????????? ??
????A??true B??false
????17????????????в????????? ??
????A??arguments ?б???????????????????в?????
????B??return ?????????????á?
????C??setInterval(fn1??1000) ????????? fn1??
????D??Date ????? getMonth() ??????????????·?С1??
????18?????????????????? ??
????A??parseInt(12.5) == parseFloat(12.5)
????B??Number('') == parseFloat('')
????C??isNaN('abc') == NaN
????D??typeof NaN === 'number'
????19????????????в????????? ??
????A??'==' ????????У?????????????????????????????????????
????B??NaN == NaN ?????? true??
????C??isNaN???ж?????????????????????????true????????false
????D????????? length ??????????????????á?
????20?????′????У?????????????????ε??? ????????ε??? ?????????ε??? ??
????function fn1() {
????var a = 0;
????function fn2() { ++a; alert(a); }
????return fn2;
????}
????fn1()();
????var newFn = fn1();
????newFn();
????newFn();
????A??1 B??2 C??0 D??3
????21?????????????н?????????ε??? ????????ε??? ??
????var a = 100;
????function fn1() {
????alert(a);
????var a = 10;
????}
????alert( fn1() );
????A??100
????B??10
????C??function fn1() { alert(1); }
????D??undefined
????22?????′??????к?arr??????? ????arr2??????? ??
????var arr = [1??2];
????var arr2 = arr.concat();
????arr2.push( arr.splice(1??0) );
????A??[1??2] B??[1??2??[2]] C??[1??2??[]] D??[1??2??3]
????23?????????????????????????? ??
????A??????? length ??????????????????
????B?????? pop() ???????????????????е????
????C??shift() ???????????????????????
????D?????? concat() ????????????????????
????24?????г?????alert????????????? ?????? ?????? ??
????var a = 10;
????function test() {
????a = 100;
????alert(a);
????alert(this.a);
????var a;
????alert(a);
????}
????test();
????A??10 B??100 c??undefined D????????
????25???????????????????????? ??
????var arr=new Array(5);
????arr[1]=1;
????arr[5]=2;
????console.log(arr.length);
????A??2 B??5 C??6 D??????
????26????JavaScript?У????У? ??????????????????????С????
????A??var date=new Date(); var hour=date.getHour();
????B??var date=new Date(); var hour=date.gethours();
????C??var date=new date(); var hour=date.getHours();
????D??var date=new Date(); var hour=date.getHours();
????27???????????????? ??
????A??null == undefined
????B??null === undefined
????C??undefined == false
????D??NaN == NaN
????28?? Math.ceil(-3.14)??????? ????Math.floor(-3.14) ??????? ??
????A??-3.14 B??-3 C??-4 D??3.14
????29?? ??????′?????????н????? ??
????var s="abcdefg";
????alert(s.substring(1??2));
????A??a B??b C??bc D??ab
????30?? ???? ECMAScript ??????????????????? ??
????A??_125dollor B??1207A C??-dollor D??this
????????????????8???
????1????????? [-1??-2??1??10??4??5??8] ?е?????????д???????????
????2????????????????????? "miao-wei-ke-tang" ???????????????????д????????????? miaoWeiKeTang????????????????????????????
????3 ?? ??????????????????? " miao v " ??? trim ????????????? trim ???????????????????????????????????
????4??д????????????????? "abcabcabcabcabcabda" ?? "ab" ??????????λ?á?
????5 ?????? js ???????????????body ?????? 100 ?? div????? div ?? 100px???? 100px???????? 1-100 ???????????????????????????????10??10?????С?
????- ?????? -
????????????????????2??????????????????÷??
????1??B
????2??CD
????3??B
????4??B
????5??C
????6??B
????7??ABCDE
????8??B
????9??B
????10??D
????11??C
????12??????ε??? A ??????ε??? D ??
????13??B
????14??A
????15??C
????16??B
????17??C
????18??D
????19??ABC
????20??????ε??? A ????????ε??? A ?????????ε??? B ??
????21??????ε??? D ????????ε??? D ??
????22??arr ??????? A ????arr2 ??????? C ??
????23??A
????24????????????? B ?????? A ?????? B ??
????25??C
????26??D
????27??A
????28??Math.ceil(-3.14) ??????? B ????Math.floor(-3.14) ??????? C ??
????29??B
????30??A
?????????????????????8???
????1????????? [-1?? -2?? 1?? 10?? 4?? 5?? 8] ?е?????????д???????????
????var arr = [-1?? -2?? 1?? 10?? 4?? 5?? 8];
????// ?????
????var max1 = Math.max.apply(null?? arr);
????// ?????
????var max2 = arr.sort(function(a?? b){
????return b - a;
????})[0];
????// ??????
????var max3 = -Infinity;
????for (var i = 0; i < arr.length; i++) {
????if (max3 < arr[i]) {
????max3 = arr[i];
????}
????}
????2????????????????????? "miao-wei-ke-tang" ???????????????????д????????????? miaoWeiKeTang????????????????????????????
????var str = 'miao-wei-ke-tang';
????function toTuoFeng(str) {
????var arrStr = str.split('-');
????for (var i = 1; i < arrStr.length; i++) {
????arrStr[i] = arrStr[i].substr(0?? 1).toUpperCase() + arrStr[i].substr(1);
????}
????return arrStr.join('');
????}
????console.log(toTuoFeng(str));
????3????????????????????? " miao v " ??? trim ????????????? trim ???????????????????????????????????
????var str = ' miao v ';
????// ????????
????function trim(str) {
????var start?? end;
????for (var i=0; i < str.length; i++) {
????if (str[i] !== '') {
????start = i;
????break;
????}
????}
????for (var i = str.length-1; i >= 0; i--) {
????if (str[i] !== '') {
????end = i;
????break;
????}
????}
????return str.substring(start?? end + 1);
????}
????// ????????
????function trim(str) {
????var start = 0?? end = str.length - 1;
????while(start < end && str[start] == '') {
????start++;
????}
????while(start < end && str[end] == '') {
????end--;
????}
????return str.substring(start?? end + 1);
????}
????console.log(trim(str));
????4??д????????????????? "abcabcabcabcabcabda" ?? "ab" ??????????λ?á?
????var str = 'abcabcabcabcabcabda';
????var arr = [];
????var n = 0;
????while(str.indexOf('ab'??n) != -1 && n < str.length) {
????arr.push(str.indexOf('ab'?? n));
????n = str.indexOf('ab'?? n) + 2;
????}
????console.log(arr);
????5?????? JS ???????????????body ?????? 100 ?? div????? div ?? 100px???? 100px???????? 1-100 ???????????????????????????????10 ?? 10 ?????С?
????- CSS -
????.box { position:relative; }
????.box div { width: 60px; height: 60px; position: absolute; }
????- HTML -
????< div class="box"></div>
????- JavaScript -
????var box = document.getElementsByTagName('div')[0];
????var str = '';
????var arr = ['red'?? 'yellow'?? 'blue'?? 'green'];
????for (var i = 0; i < 100; i++) {
????str += ' < div style="left:' + i%10*60 + 'px; top:' + Math.floor(i/10)*60 + 'px; background:' + arr[i%arr.length] + ';">' + (i+1) + '</div>';
????}
????box.innerHTML += str;
????????????к????????????????м???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11