JS Basic question

Source: Internet
Author: User

function PrintArray (arr) {

for (var i in arr) {

if (Arr[i] instance of Array) {

PrintArray (Arr[i]);

}else{

document.write (arr[i]+ ");

}

}

}

var data=[1,[20,21],[[301,302],[310,[311]];

PrintArray (data);

After the above code is run, the page output is?

Answer: 1 20 21 301 302 310 311

The function PrintArray uses recursion to output each member of the array one by one, separated by a space

The instanceof operator is used to test whether an object has a prototype property of a constructor in its prototype chain

What is a stack?

A stack is a linear table with limited operations, and the term system allows only one end of the table to insert and delete operations. This end is called the top of the stack, and the opposite end is called the bottom of the stack. Inserting a new element into a stack, also known as a stack, into a stack, or a stack, is to put the new element above the top of the stack, making it a new stack top element, the deletion of elements from a stack, called a stack or a stack, it is to remove the top element of the stack, so that its adjacent elements are called the new top

Push, press in from the end

Pop, remove from end

Shift, DELETE from first

Unshift from First press in

What is a regular expression? How do I use regular expressions?

The regular expression itself is a string, consisting of some ordinary string and a special string of expressions that describe a particular character rule.

There are two kinds of application of the expression in JavaScript;

1, combined with the Replace search match method of the string object, implements the substitution, finding and matching of strings;

2, defines the regular expression object, implements the complex matching operation to the string.

Varregexp=/\bdo\b/ig;
VarData=' He does told to Do,do. ';
Console. log (data. Search (regexp));
Output 16
\b Represents the letter boundary
IG is usually linked together
Indicates case insensitive. G means looking from beginning to end.
Search indicates that the index is returned after it is found


Read the following code

function Add (num) {
try{
Num=number (num);
if (IsNaN (num) {
throw new Error (' Argument is NaN ');
}
Console.log (' Try block end ');
}catch (e) {
Console.log (' catch block ');
Return
}finally{
Console.log (' finally block ');
}console.log (' function end ');
}
Add (' 10x ');
Ask the above code to run, the output is?
Answer:
First, the catch block is output and the finally block
Because a try Catch statement is a statement that is used as an exception handler, a catch is taken after a program error
So the output catch block;
The finally will always run, so the output continues. When an exception occurs, the program is rolled out, so no more statements are executed.



JS Basic question

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.