[JavaSript knowledge training - Basics] [12 Javascript object programming] [JavaScript language basics] [11 JavaScript objects] []

Posted by katie77 on Thu, 06 Jan 2022 05:23:43 +0100

9. JavaScript overview

1, JavaSript knowledge training - Basics

1. JavaScript is a scripting language that runs on ().
B. Client

2. JavaScript code is usually embedded into html documents with () tags.
D,script

3. The only tool for writing JavaScript programs is a plain text editor.
B. Error

4. After defining a variable with var, if no value is given, its value is null, that is, null.
A. Error
5. JavaScript does not declare the data type of variables. Variables can be used directly
A. Right

10. Fundamentals of JavaScript language (5)

1, JavaScript knowledge training: JS function

1. Of the following options, () can be used to check whether a value is an infinite number.
B,isFinite()
2. The value of the function parseInt(15.36) is ()
A,15
3. The value of the function parseFloat(15.36) is ()
D,15.36

4. The value of s in the following code is ()

var a="100"
var b=100;
var s=a+b;
alert(parseInt(s));

C,100100
5. The return value of isNaN("abc") is () C,true

2, JavaScript knowledge training: JS branches and loops

1. After executing the following statement, the value of c is (D, 4).

var a=2,b=1,c=3;
if(a<b){
    c=0;
}
else{
    c++;
}

2,var a=false;
var x = a?"A":"B";
In the above snippet, the value of x is () B, B
3. The following JavaScript loop statements () are correct
D,for(i=0;i<10;i++){...}
4. There is a statement "var x = 0; while() {x + = 2;} To make the while loop body execute 10 times, the loop judgment formula in the blank should be written as?
C,x<20
5. Analyze the following JavaScript snippet: the output is (B, string)

var s1=15;
var s2="string";
if(isNaN(s1)){
document.writeln(s1);}
if(isNaN(s2)){
document.writeln(s2);}

3, JS conditional statement

Level 1: if else type

function mainJs(a) {
    a = parseInt(a);
	//Write your code here
	/********** Begin **********/
   return a<60 ? "unpass" : "pass";
	/********** End **********/
}

Level 2: switch type

function mainJs(a) {
    a = parseInt(a);
	//Write your code here
	/********** Begin **********/

	switch(a){
		case 82414:
			return "Superior";
			break;
		case 59600:
			return "Huron";
			break;
		case 58016:
			return "Michigan";
			break;
		case	25744:
			return "Erie";
			break;
		case 19554:
			return "Ontario"
			break;
		default:
			return "error";
			break;
	}
    
    
	/********** End **********/
}
    

4, Fundamentals of JavaScript syntax: JS loop statements

Level 1: while type

function mainJs(a) {
    a = parseInt(a);
	//Write your code here
	/********** Begin **********/
    var sum=0;
    var i=2;
    while(i<=a){
        var j=2;
        while(j<i){
            if(i%j==0){
                break;
            }
            j++;
        }
        if(j==i){
            sum+=i;
        }
        i++;
    }
    return sum;
	/********** End **********/
}

Level 2: do while type

function mainJs(a,b) {
    a = parseInt(a);
    b = parseInt(b);
	//Write your code here
	/********** Begin **********/
	var sum = 0;
	var i = a+1;
    while(i<b){
		sum += i;
		i+=1;
	}
	return sum;
	/********** End **********/
}

Level 3: for type

function mainJs(a,b) {
    a = parseInt(a);
    b = parseInt(b);
	//Write your code here
	/********** Begin **********/
	var sum = 1;
	if(b-a<=1) return 1;
    for(var i =a+1; i<b; i++){
		sum *= i;
	}
	return sum;
	/********** End **********/
}

5, Fundamentals of JavaScript syntax: JS operators

Level 1: JavaScript knowledge training - Operator

1. In JavaScript, two integers are divided (/), and the result is also an integer.
B. Error
2,x={x:1};y={y:1};z=1;n='1 'the following result is true(
D,z == n

3. Assume that val has been declared and defined as any value. Ternary operator (val! = = '0')‘ define’:‘undefine’; The return value of is ()
A,define

4. Assuming the following code, the return result of a(10) is ()

  function a(a){
     a^=(1<<4)-1;
     return a;
     }

A,5
5. In the following javascript code, the output result of the last alert is ()

  var msg='hello';
  for(var i=0;i<10;i++){
      var msg = 'hello'+i*2+i;
     }
  alert(msg);

C,hello189

Off 2: arithmetic operators

function mainJs(a,b) {
//Write your code here
/***********Begin**********/
a1 = parseInt(a);
b1 = parseInt(b);
c = (a1 %b1).toString();
a.toString();
b.toString();


/*********End************/
    return a+b+c;
}

Level 3: comparison and logical operators

function mainJs(a,b) {
//Write your code here
/********Begin***************/
return a>b ? a&&b : !a

/**********End****************/
}

Off 4: conditional operator

function mainJs(a,b) {
//Write your code here
/*********begin*********/
return a>b ? a:b;

/*********end*********/
}

Level 5: operator priority and Associativity

function mainJs(a,b) {
    var a = parseInt(a);
    var b = parseInt(b);
//Write your code here
/*********begin*********/
result1 = (a-1+b)*b;
c = result1 ==24 ? 1: 0;
d = 4;
e = c*d+d;
/*********end*********/
    return e;
}

11. JavaScript object (7)

1, JavaScript knowledge training -- string object

Level 1: JavaScript knowledge training - String object

1. In JavaScript, the following charAt() and indexOf() methods for String objects are correctly understood as ()
A. The charAt() method gets the character at the specified index position
2. The method of the String object does not include ().
D,length()

3. The properties of the String object do not include ()
B,indexOf
4,var str="King of the world"; document.write("the 9th to 3rd characters in the string are:" + str.substring (8,2) + "< br / >");
The display result is ().
B,ng of t
5. The correct expression for the string str="welcome to taiyuan" is ().
C. The value returned by str.toUpperCase(str) is WELCOME TO TAIYUAN

2, JavaScript knowledge training: array objects

Level 1: JavaScript knowledge training: array objects

1. Append an element 10 to the end of the array. The correct syntax is ()
C,array.push(10);
2,var arr =[1,2,3,4,5,6];
arr.splice(2,3);
alert(arr);
The correct result of running the above code is ().
A,1,2,6
3. After executing the following code, the value of array myArr is ()
var myArr = [1,2,3,4,5];
myArr.shift();
B,[2.3.4.5]
4. JavaScript program segment "var arr = new array (1,2,3,4); document. The result of "write (arr. [3])" executed in the browser is ()
D,4
5. Analyze the following JavaScript snippet

   a=new Array(2,4,4,5,6);
   sum=0;
   for(i=0;i<a.length;i++){
    sum+=a[i];
    }
    document.write(sum);

The output is ().
A,21

3, JavaScript knowledge training: Date object

1. The following description of the Date object in JavaScript is correct ()
C. getHours() returns the number of hours of the Date object, with a value between 0 and 23
2. In JavaScript, the following () statement can correctly obtain the hour value of the current time.
D,var date = new Date();
var hour = date.getHours();
3. If today is Friday, December 31, 2021, after running the following code, the result is ()

var now = new Date();
alert(now.getDay());

B,5
4. In JavaScript, which of the following code can execute the expression() after 1 second
D,setTimeout(expression,1000);

5. If today is December 31, 2021, the following JavaScript code will be displayed on the web page ().

  var now=new Date();
  var year=now.getYear();
  var month=now.getMonth();
  var date=now.getDate();
  document.write(year+""month+""+date);

C,2021 11 31

4, JavaScript knowledge training: mathematical objects

1,Math. The result of ceil (- 3.14) is ().
B,-3
2,Math. The result of floor (- 3.14) is ().
C,-4
3,Math. The result of round (- 3.14) is ().
B,-3
4. The result of the JavaScript program segment "var x=8.167589;var n=x.tofixed(2); document.write(n)" running is ()
D,8.17
5. The result of running the JavaScript program segment "var x=8.167589;var n=x.toPrecision(2); document.write(n)" is ()
B,8.2

5, JavaScript objects: Math, date

1st off Math class

function mainJs(a) {
    a = parseInt(a);
	//Write your code here
	/********** Begin **********/
	with (Math) {
		return max(ceil(a),floor(a) ,round(a) , sqrt(a),sin(a))  +min(ceil(a),floor(a) ,round(a) , sqrt(a) ,sin(a));
	}
	
    
	/********** End **********/
}

Off 2: Date class

function mainJs(a) {
    a = parseInt(a);
    var date = new Date(a);
    /*********Begin*********/
    var year = date.getFullYear();
    var month = date.getMonth() ;
    var day = date.getDate();
    var week = date.getDay()  ;

   return year + ','+month +','+ day +','+week;

    /*********End*********/
}

6, JavaScript objects: strings

Off 1: find the position of the string

function mainJs(a,b) {
	//Write your code here
	/********** Begin **********/
     var c=a.indexOf(b);
     var sum=0;
     while(c>=0){
         sum +=c;
         c=a.indexOf(b,c+b.length);
     }
    
    return sum;
    
	/********** End **********/

}

Off 2: find the character at the specified position

function mainJs(a) {
	//Write your code here
	/********** Begin **********/
    
    var i=0;
    var b="";
    while(i<6){
    
    b+= a.charAt(i);
   
    i++;
    }
    
    return b;
	/********** End **********/
}

Off 3: String interception

function mainJs(a,b) {
	//Write your code here
	/********** Begin **********/
     var c=a.indexOf(b)
    if(c!=-1){
        return(a.slice(0,c)+a.slice(b.length+c))
    }
    return a;
    
	/********** End **********/
}

Level 4: string segmentation

function mainJs(a) {
	//Write your code here
	/********** Begin **********/
     var spaceArray = a.split(" ");//Split by space
    var commaArray = a.split(",");//Separated by commas
    return spaceArray.length+commaArray.length-1;
    
	/********** End **********/
}

7, JavaScript objects: arrays

Level 1: array creation, read-write and length

var array1 = [1,2,3,"js",4,true,"hello"];
var array2 = [true,true,"java",2.1];
function mainJs(a) {
	//Write your code here
    a = parseInt(a);
    /*********begin*********/

 if(a==array1.length){
        return "hello";
    }else{
        return 2.1 ;
    }
    /*********end*********/
}

Level 2: increase or decrease of array elements

var testArray = [12,"java","js","c","c++",24,36,"python","c#","css"];
function mainJs(a,b) {
    a = parseInt(a);
    b = parseInt(b);
    //Write your code here
    /*********begin*********/
  for (var i=0;i<a;i++){
    testArray.unshift(testArray .pop());
    }
    return testArray[b];

    /*********end*********/
}

Level 3: common methods of arrays

function mainJs(myArray) {
    myArray = myArray.split(",");
    //Write your code here
    /*********begin*********/
     var s=0;
      var a=new Array();
      while(s<myArray.length){
       s=myArray.indexOf("a",s);
       if(s!=-1){
              a.push(s);
               s++;
              }
       else{
            break;
             }
       }
           s=0;
          var b=new Array();
       while(s<myArray.length){
           s=myArray.indexOf("b",s);
           if(s!=-1){
           b.push(s);
           s++;
             }
           else{
                break;
          }
         }
            return a.concat(b);



    /*********end*********/
}

12 Javascript object programming

1, JavaScript knowledge training: objects and events

1. The following describes the internal objects of javascript. The correct ones are ()

A,
The History object contains the URL that the user (in the browser window) has visited

B,
The Location object contains information about the current URL

C,
The Window object represents an open Window in the browser

D,
The Navigator object contains information about the browser

2. The following description of events in Javascript is incorrect ()
D. onchange: event triggered when a field is selected

3. If the following picture tag is included in the html page, the () statement in the option can hide the picture.
<img id=pic src=sunset.jpg />
D,document.getElementById('pic').style.display = none;
4. In the tree structure of HTML document, the () tag is the root node of the document and is located at the top level of the structure.
A,<HTML>
5. Which appearance parameter of the open() method can set whether to display the scroll bar? ( )
C,scrollbars

Topics: Javascript Front-end html