JS Exercises Notes

Source: Internet
Author: User

Tags: Sub float relative shift Val nan arguments select question Strong

Javascrip Test questions:

one, the choice of questions (2 points per question, multiple choice of choice, choose not to divide)

1, the analysis of the next segment of the code output is ()
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 B. C. D. 12

2. The following argument about array array objects is incorrect ()
A The sort function can be used for sorting data in an array, and if the sort effect is not expected, you can add a sort function parameter to the sort function.
B Reverse for reverse permutation of array data
C Add a new element to the last position of the array, and you can use the Pop method
D The Unshift method is used to delete the first element of the array

3, the following code runs the result is the output ()
var a = b = 10;
(function () {
var a=b=20
})();
Console.log (b);
A Ten B. C. Error D. Undefined

4, the following code after running the result is output ()
var a=[1, 2, 3];
Console.log (A.join ());
A 123 B. C. 1 2 3 D. [A]
5, in JS, ' 1555 ' +3 of the operation result is ()
A 1558 B. 1552 C. 15553 D. 1553

6, the following code to run after the result of the popup is ()
var a = 888;
++a;
alert (a++);
A 888 B. 889 C. 890 D. 891

7, about the variable naming rules, the following statement is correct ()
A The first character must be an uppercase or lowercase letter, an underscore (_), or a dollar symbol ($)
B Characters except the first letter can be letters, numbers, underscores or dollar symbols
C Variable name cannot be a reserved word
D The length is arbitrary.
E. Case sensitive

8, which of the following expressions will return a value of false ()
a.! (3<=1)
B (4>=4) && (5<=2)
C ("a" = = "A") && ("c"! = "D")
D (2<3) | | (3&LT;2)

9, the following code, K operation result is ()
var i = 0,j = 0;
for (; i<10,j<6;i++,j++) {
K = i + j;
}
A B. Ten C. 6 D. 12

10, var x = 1; function fn (n) {n = n+1}; y = fn (x); The value of Y is ()
A 2 B. 1 C. 3 D. Undefined

11, [1,2,3,4].join (' 0 '). The execution result of Split (") is ()
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, the following code to run the result is: the first time to play () the second bomb ()
function fn1 () {
Alert (1);
}
Alert (FN1 ());
A 1
B Alert (1);
C function fn1 () {alert (1);}
D Undefined

13, after the following code is run, the result is ()
FN1 ();
var fn1 = function (a) {alert (a);}
A 1 B. Program error C.     Alert (1); D Undefined

14,var n = "Miao wei ke Tang". indexOf ("Wei", 6); The value of n is: ()
A -1 B. 5 C. Program error D. -10

15, the following description of the substring () method is incorrect ()
A A total of two parameters, omitting the second parameter means extracting from the beginning of the argument, intercepting to the end of the string.
B The size of the two parameters is compared before extraction and the position is adjusted according to the size.
C You can receive negative arguments, and negative numbers indicate the position of the digits from the backward forward.
D If no parameters are set, the entire string is returned directly.

16,alert ("A" > "9") the result of the operation is correct ()
A True B. False

17, which is incorrect in the description below ()
A All parameters in the actual incoming function are saved in arguments.
B Return can only be used inside a function.
C SetInterval (fn1,1000) will only invoke fn1 once.
D The Date object's GetMonth () gets a value that is 1 smaller than the actual month.

18, the following equation is set up to be ()
A parseint (12.5) = = parsefloat (12.5)
B Number (') = = parsefloat (")
C IsNaN (' abc ') = = NaN
D typeof NaN = = = ' Number '

19, which is incorrect in the description below ()
A ' = = ' In the comparison process, not only compares the values on both sides, but also compares the data types on both sides.
B The result of Nan = = Nan is true.
C IsNaN, determines whether the passed in parameter is a number, returns true for the number, or returns false
D The length of the string can only be obtained and cannot be set.

20, what happens in the following code: first Bounce (), second Bounce (), third bounce ()
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, the following code to run the result is: the first play (), the second bounce ()
var a = 100;
function fn1 () {
alert (a);
var a = 10;
}
Alert (FN1 ());
A 100
B 10
C function fn1 () {alert (1);}
D Undefined

22, after the following code is run, the result of Arr is (), the result of ARR2 is ()
var arr = [+];
var arr2 = Arr.concat ();
Arr2.push (Arr.splice (1,0));
A [+] B.     [1,2,[2]] C     [1,2,[]] D [A]
23, the following description of the array is correct ()
A The length of the array can be either obtained or modified.
B Calling the Pop () method does not modify the values in the original array.
C The return value of the shift () method is the length of the new array.
D Calling the Concat () method modifies the value of the original array.

24, alert pops up in order in the following procedure: (), (), ()
var a = 10;
function Test () {
A = 100;
alert (a);
alert (THIS.A);
var A;
alert (a);
}
Test ();
A Ten B. C. Undefined D. Program error

25, analyze the following code, the result of the output is ()
var arr=new Array (5);
Arr[1]=1;
arr[5]=2;
Console.log (arr.length);
A 2 B. 5 C. 6 D. Error

26, in JavaScript, the following () statement correctly obtains the time-out value of the current system.
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, select the option with the result true ()
A Null = = undefined
B Null = = undefined
C Undefined = = False
D Nan = = Nan

The result of Math.ceil (-3.14) is (), the result of Math.floor (-3.14) is ()
A -3.14 B. -3 C. -4 D. 3.14

29, read the following code, and the result in the page is ()
var s= "ABCDEFG";
alert (s.substring);
A A B. b C. BC D. Ab

30, the following ECMAScript variable naming format is correct ()
A _125dollor B. 1207A C. -dollor D. This


Ii. Questions and Answers (8 points per question)

1, find the maximum value in the array [ -1,-2,1,10,4,5,8], write at least two methods?

2, encapsulates a function that capitalizes the string "Miao-wei-ke-tang" from the start of the second word, then miaoweiketang the string and returns. (Note: Encapsulated as a function)

3, encapsulates a function that implements the TRIM function of the string "Miao V", but does not use the Trim method, removes the string before and after the space, and returns the processed string.

4, write a method to find out the number and position of "AB" in the string "Abcabcabcabcabcabda".

5, please use the JS code to complete the following requirements: The body generated 100 div, each div width 100px, high 100px, the content is 1-100 of its own serial number, color by red, yellow, blue, green alternating discoloration, 10 rows 10 column arrangement.



The above test questions, there is no classmate? If you can't answer more than half of them, maybe you should seriously consider a thorough, systematic, in-depth JavaScript study.

Well, the answer is coming soon!

Note Oh, do not first look at the following answer, or the first test before you see the answer Oh ~ ~



-The answer is as follows-

One, the choice answer: (2 points per question, multiple choice of choice, less than the choice of not divided)

1, B
2. CD
3, B
4, B
5, C
6, B
7, ABCDE
8, B
9, B
10, D
11, C
12. First Play (A) second projectile (D)
13, B
14, A
15, C
16, B
17, C
18, D
19. ABC
20. First play (a), second projectile (a), third projectile (B)
21. First Play (d), second bomb (d)
22. The result of Arr is (A), the result of ARR2 is (C)
23, A
24. Pop-up in order (b), (A), (b)
25, C
26, D
27, A
The result of 28, Math.ceil (-3.14) is (B), the result of Math.floor (-3.14) is (C)
29, B
30, A

Answer to the question : (8 points per question)

1. Find the maximum value in array [-1,-2, 1, 10, 4, 5, 8] and write at least two methods?

var arr = [-1,-2, 1, 10, 4, 5, 8];

First Kind
var max1 = Math.max.apply (null, arr);

The second Kind
var max2 = Arr.sort (function (A, b) {
return b-a;
}) [0];

Third Kind
var max3 =-infinity;
for (var i = 0; i < arr.length; i++) {
if (Max3 < arr[i]) {
Max3 = Arr[i];
}
}



2. Encapsulate a function, capitalize the string "Miao-wei-ke-tang" from the beginning of the second word, and then spell the string Miaoweiketang and return. (Note: Encapsulated as a function)

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, encapsulates a function, the string "Miao V" to achieve the functionality of trim, but do not use the Trim method, remove the string before and after space, return the processed string.

var str = ' Miao V ';

The first of these methods
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);
}

The second method of
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. Write a method to find out the number and position of "AB" in the string "Abcabcabcabcabcabda".

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, please use the JS code to complete the following requirements: The body generated 100 div, each div width 100px, high 100px, the content is 1-100 of its own serial number, color by red, yellow, blue, green alternating discoloration, 10 rows 10 column arrangement.

-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 <; 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;

Nothing but the choice of the problem, the result is a lot of wrong, but there is nothing, is still in the most basic stage of learning, as long as every day can progress a little better, here are my notes to finish the choice question:

1. We can use the charCodeAt () method to view a number of character encodings, such as: ' 1 '. charCodeAt (0) = 49; ' 9 '. charCodeAt (0) = 57.

The comparison of strings in 2.js will only compare the first character, such as ' 12 ' and ' 9 ': ' 1 ' character encoding is 49, and ' 9 ' character is encoded as 57,57>49 so alert (' < ' 9 ') has a value of true.

Use push in 3.js to add elements to an array or string, use Unshift to add elements to the front of an array or string, and use pop to remove elements from an array or string, and shift the element from the array or string before it.

4.js, like Java, is case-sensitive, and the naming convention for variables is similar to Java, with only the following lines, the dollar sign $, and the beginning of the character.

5.Date objects use the Getmonths () method to get the number of months to 1 less than the actual month.

The value of the 6.isNaN () method is of type Boolean.

The value of 7.Number ("") is 0;parsefloat ("") with a value of Nan,parseint ("") that is Nan.

The value of 8.typeof NaN = = = ' Number ' is true.

9. Local variables in closures are persisted in memory and are not automatically cleared after a function call.

10. In the array concat, join, slice three methods will return the new array, and the other methods will not return the new array, they will change the original array.

11.splice (1,0) means to delete 0 elements starting at index 1, so if var a = splice (1,0)//a = [].

12. The length of the array can be either read or modified.

The result of 13.null = = undefined is true,null = = = Undefined result of False,nan = = NaN is false.

14.math.ceil (): Whether positive or negative, it is a large integer change, such as: Math,ceil ( -3.4) = -3,math.ceil (3.4) = 4.

15.math.floor (): either positive or negative, it changes to a small integer, such as: Math.floor ( -3.4) = -4,math.floor (3.4) = 3.

16.math.round (): If it is a positive number, it is rounded, but if it is negative, it is five six.

JS Exercises Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: