js basic test questions and answers (1)

1. Multiple choice questions (30 questions in total, 2 points for each question)
1. The following code will pop up what is var num1=“1” ;var num2=1 alert(num1-num2);

A 0

B 11

C 1+1

D error

Correct answer: A
analysis:
subtract, perform hermit conversion, all are numbers

2. The following code, what will pop up var num1="hi" var num2=1 alert(num1+num2);

A hi1

B 1

C hi

D error

Correct answer: A
parsing:
string splicing

3. In JS, the result of "1555"+3 is

A 1558

B 1552

C 15553

D 1553

Correct answer: C
analysis:
15553

4.parseInt("20.2aa") The return value is

A 20

B 20.2

C 20.2aa

D
NaN
correct answer: A
analysis: 20

5. The output of the analysis is

function sum(a){ a = a + 2; }

var res = I (2);

console.log(res);

A 2

B 4

C NaN

D undefined

Correct answer: D
Resolution:
undefined

6.var a = false;

var x = a? “A” : “B”;

The final value of x

A A

B B

C true

D false

Correct answer: B
Analysis: B

7. The following variable names are legal

A 5show

B return

C $user

Have d

Correct answer: C
analysis:
variable name cannot start with a number, A is wrong; BD is a keyword, C is correct

8. The script file myJs.js needs to be quoted on the html page. In the following statement, the correct one is

A <script href="myJs.js" type="text/javascript" />

B <script src="myJs.js" type="text/javascript" />

C <script href="myJs.js" type="text/javascript"></script>

D <script src="myJs.js" type="text/javascript"></script>

Correct answer: D
analysis:
script is a double tag, src import file

9. The output of the code is

var a = 3;

var b = 2;

var c = (a + 2) / b;

document.write ©;

A 2.0

B 2.5

C 16.0

D (3+2)/2

Correct answer: B
analysis:
js weak type, (2+3)/2=2.5

10. The output result of the code is

function add(){

var sum = 1 + 2;

console.log( sum ) ;

}

console.log(sum) ;

A output two 3

B outputs a 3

C program error

D outputs an undefined

Correct answer: C
analysis:
sum is a local variable, the global environment is not defined

11. The data type detected by typeof null is

A null

B number

C object

D undefined

Correct answer: C
analysis:
null is an empty object

12. The result of parseInt("12a") is

A NaN

B 12a

C 0

D 12

Correct answer: D
analysis:
because of the conversion rules of parseInt(): skip the empty characters at the beginning and the end, perform the conversion from left to right, and stop when it encounters the first unknown number, so the answer is D

13. Which of the following expressions will return false

A !(3<=1)

B (4>=4)&&(5<=2)

C 2<3

D (2<3)||(3<2)

Correct answer: B
analysis:
&& left and right sides are false; the entire expression is false

14. Which of the following statements about loop is correct

A while loop will run at least once

B do...while loop will run at least once

C for loop will run at least once

D switch loop will run at least once

Correct answer: B
Analysis:
do…while is executed first and then judged. No matter whether the condition is established or not, it will be executed at least once

15.for(var i = 0; i < 10; i++){ i++; }

What is the value of console.log(i)?

A 10

B 9

C undefined

D 7

Correct answer: A
analysis:
i++ is finally 10; not less than 10; end the for loop; at this time i is 10

16. The execution result of the following code is

var a = 20;

function foo(){

console.log(a) ;

var a = 10;

console.log(a) ;

}

foo();

A 20 10

B 10 10

C 20 20

D undefined 10

Correct answer: D
analysis: the a in the
function will be promoted; so the first a is undefined; a is assigned a value of 10; so a is 10; the D option is correct

17. Have the following JS code:

var x = 10; var y = 20;

var z = x<y ? x++ : ++y ;

console.log( ‘x=’ + x + ‘; y=’ + y + ‘; z=’ + z);

The result of its operation is

A x=11; y=21; z=11

B x=11; y=20; z=10

C x=11; y=21; z=10

D x=11; y=20; z=11

Correct answer: B
analysis:
x=11; y=20; z=10

18. View the following code:

function f1( ){

console.log(x);    

var x = 10;    

++x;

console.log(x);

}

f1 ();

The result after execution is

A program error

B undefined 和 10

C undefined 和 11

D 10 and 11

Correct answer: C
analysis:
undefined and 11

19. The correct syntax for referencing an external script named "xxx.js" is

A

B

C

D

Correct answer: C
analysis:
JS script introduction with src attribute

20. The following code, what will pop up var a; alert(a);

A error

B a is not define

C undefined

D 0

Correct answer: C
analysis:
variable promotion

21. The following code, what will pop up alert(a); var a=12;

A error

B a is not define

C undefined

D 12

Correct answer: C
analysis:
variable promotion

22. The composition of JavaScript does not include
A ECMAScript
B DOM
C BOM
D document
Correct answer: D
analysis:

23.console.log( typeof 123 === “number”)

A error

B true

C false

D 123

Correct answer: B
analysis:
get the "number" of the string, so the type and value are equal to be congruent

24. The output result of the code is

function fnMax(a,b,c){

var a,b,c;    

var max = a > b ? a : b;    

if(c > max){        max = c;    }    

alert(max); 

}

fnMax(8,2,5);

A 5

B 2

C 8

D 10

Correct answer: C
analysis:
the maximum value of 8, 2, 5 is 8

25. Which of the following is not a feature of javascript

A Javascript is a scripting language

B Javascript is event driven

C Javascript code needs to be manually compiled before it can be executed

D Javascript is platform independent

Correct answer: C
analysis:
JavaScript is an event-driven and platform-independent scripting language

26. The following code, what will pop up var num1="1"; var num2=1 alert(num1-num2);

A 0

B 11

C 1+1

D error

Correct answer: A
analysis:
subtract, perform hermit conversion, all are numbers

27.console.log(typeof typeof 123456), what to print in the console

A 123456

B number

C string

D object

Correct answer: C
analysis: the
first typeof 123456 returns "number"

Then typeof "number" returns "string"

28.console.log( (2==true)+1) will pop up
A true
B false
C 1
D 2
Correct answer: C
analysis:

29. The following code, what will pop up var num1=“1”; var num2=1 alert(num1+num2)

A 2

B 11

C 1+1

D error

Correct answer: B
analysis:
hermit conversion

30. The result of the following expression is false

A !""

B !{}

C !undefined

D !!5

Correct answer: B
analysis:
use if to judge an empty object and the result is still true

2. Multiple choice questions (indefinite choice) (20 questions in total, 2 points for each question)
1. Which of the following are loop sentences

A while

B do…while

C for

D switch

Correct answer: A, B, C
Analysis:
while, do...while, for

2. Which of the following is a selection structure control statement:

A if

B for

C switch

D while

Correct answer: A, C
analysis:
fixed keywords

3. In the following options, the data type is number type.

A “1”

B 1

C true

D NaN

Correct answer: B, D
Analysis:
1, NaN

4. The following statement gets the value true

A “1” == 1

B 1===“1”

C “2” > “19”

D “2”==19

Correct answer: A, C
analysis:
Comparing two equal signs will have implicit type conversion, only the value is equal, three equal signs must be equal in type and value at the same time, the result is true, so A is wrong to B

The size comparison between strings is based on the ACSII encoding size. The ASCII code of "2" is larger than the ASCII code of "1", so C is correct

Comparing the size of a number with a string will implicitly convert the string to a number, ie 2>19, the D option is wrong

5. The following statement gets the value of 2

A 1 + ‘1’

B 8 % ‘3’

C ‘1’ + ‘1’

D ‘4’ - 2

Correct answer: B, D
analysis:
A is string splicing, the result is: "11"; B "3" will implicitly convert bit 3, the result is 8%3=2; C is string splicing, the result is "11" "; D"4" will be implicitly converted to 4, and the result is 4-2=2

Therefore, the answer is BD

6. Which of the following are keywords

Have a

B function

C case

D All of the above are keywords

Correct answer: A, B, C, D
Analysis:
var declares the keyword of the variable; function declares the function of the keyword; case selects the branch of the keyword

So the answer is ABCD

7. The following are the basic data types of JavaScript

A Object

B number

C string

D boolean

Correct answer: B, C, D
Analysis:
Object is a reference type

8. Which of the following operators are correct

A ++

B –

C &&

D >=

Correct answer: A, B, C, D
Analysis:
self-increment, self-decrement, logical AND, greater than or equal to

9. What are the JavaScript operators

A assignment operator

B arithmetic operators

C relational operators

D logical operator

Correct answer: A, B, C, D
analysis:
assignment operator =, mathematical operator +-* / %, unary operator ++ --, logical operator && ||!

10. The basic components of JavaScript include

A DOM

GOOD GOOD

C jQuery

D ECMAScript

Correct answer: A, B, D
analysis:
the basic components of JavaScript include DOM, BOM and ECMAScript

11. Which of the following are loop statements

A switch

B for

C while

D do…while

Correct answer: B, C, D
analysis:
there are three loop statements for while do...while; switch is the selection structure

12. The parameters of the function are divided into

A parameter

B actual parameter

C 有参

D No parameters

Correct answer: A, B
analysis:
parameters are divided into actual parameters and formal parameters

13. Which of the following are basic data types

A object

B boolean

C string

D number

Correct answer: B, C, D
analysis:
null and undefined are special data types;

14. The actual parameters in the function can be

A constant

B variable

C can only be a variable

D can only be a constant

Correct answer: A, B
analysis:
actual parameters can be variable constants, formal parameters can only be variables

15. Logical operators are

A >

B <

C ||

D &&

Correct answer: C, D
analysis:
There are three logical operators && ||! ; The AB option is to compare

16. Which parts of javascript consist of

A js

B ECMAScript

C DOM

D GOOD

Correct answer: B, C, D
Analysis:
BCD

17. The following is the correct way of declaring variables and assignments

A var _myName = 12a

B var _myName = “12a”

C was myName = 12

D var $myName = true

Correct answer: B, C, D
analysis:
A option 12a is a string, not a pure number, the string should be quoted

Which of the following methods can be used to convert the string "123" into a numeric value

A Number()

B parseInt()

C parseFloat()

D Boolean()

Correct answer: A, B, C
Analysis:
Boolean() into a Boolean value

19. Which of the following are relational operators?

A >

B >=

C <

D <=

Correct answer: A, B, C, D
Resolution:
relationship

20. Which of the following are logical operators?

A &&

B ||

C !

D None of the above is correct

Correct answer: A, B, C
analysis:
logical operators

Guess you like

Origin blog.csdn.net/weixin_49299412/article/details/107470188