JS Face questions and Answers

Source: Internet
Author: User
one, JS closure.
f = function () {return true;};
g = function () {return false;};
(function () {
if (g () && [] = =![]) {
F = function f () {return false;};
function g () {return true;}
}
})();
Alert (f ()); True or False?
------------------------
Answer:
(function () {
if (g () && [] = =![]) {
should be treated as if ((g () && []) = =![])
Because G () is false, the &&[] doesn't work, and the whole thing is false.
//! [] Also false so if is set into an if block
F = function f () {return false;};
Re-define F
function g () {return true;}
That's no use.
}
})();
Alert (f ());
False

Second, intercept the string ABCDEFG EFG
Abcdefg
<script type= "Text/javascript" >
var mytext=document.getelementbyidx_x_x ("text");
var myvalue=mytext.innerhtml;
var jiequ=myvalue.substring (myvalue.length-3,myvalue.length);
Alert (jiequ)
</script>

Three, write the results of the operation
Alert (typeof (NULL))//Object
Alert (typeof (undefined))//undefined
Alert (typeof (NaN))//number
Alert (nan==undefined)//False
Alert (Nan==nan)//False
var str= "123ABC";
Alert (typeof (str++))//number
Alert (str)//NaN
write out the return result of function Datedemo, the system time is assumed to be today
function Datedemo () {
var d, s= "Today's date is:";
D = new Date ();
S + + d.getmonth () + "/";
S + + d.getdate () + "/";
S + + d.getyear ();
return s;
}

Result: Today's date is: 7/17/2010

Write the result of the program running.
For (i=0, j=0; i<10, j<6; i++, J + +) {
K = i + j;

Result: Ten(Beware of traps)


1. How to remove duplicate strings with regular , only one

var str= "aaaebbbcccddd";
str = str.replace (/(.) \1+/g, ' $ '

Alert (str)

2. converts the first letter of all words in a string to uppercase

Name = ' AAA bbb CCC '; Uw=name.replace (/\b\w+\b/g, function (word) {return word.substring (0,1). toUpperCase () +word.substring (1);});
Alert (UW)


1. Which of the following will be an error in javascript:
var a= ();
var a=[];
var a={};
var a=//;
What are the reserved words in 2.JAVA, the more the better, more than 10.
There are several ways of declaring in 3.CSS.
4. Write out the Open-source projects or software you know, and explain their benefits and roles.
Best Answer
1,var a= (), var a=//, error      two No.  ---------------------------------  2,java.   int  char  while  for  do  switch  void  double  float  unsigned& nbsp long  try  abstract   super  extent  bool  break  case  catch  class& nbsp Delegate foreach in   static  void  Public Private protected internal  et cetera   too much   3,&nbs p;   this question a bit do not know how to answer, in the end what statement is meaning.   is declaring that a CSS already exists has three kinds of:    1. Import an existing CSS file   <link rel= "stylesheet" type= "Text/css" "href=" " >    2. Declare a CSS code snippet directly in hard:  <style type= "Text/css" >        .....  </style>    3. Declare the use of css:  style= "color:red" directly in the page elements;     If you are declaring a CSS class, there are three kinds of:  direct-signed signatures as CSS class names:  tagname{...}   Declares the:    #ID {...} with the element ID as the CSS class.}   Custom CSS class name:         . classname{}   --------------------------------------------------------------  4, open source      client script Just say extjs    she can be used to develop RIA also that rich client Ajax applications are written in JavaScript, primarily for creating front-end user interfaces, is a front-end Ajax framework unrelated to the background technology. Therefore, ExtJS can be used in a variety of development languages such as. Net, Java, PHP and so on.   Also, using this framework allows you to implement a very beautiful and standard Web page control interface directly with a single line of code, and you can use code-invoked controls to replace the current popular page layout, as WinForm programs do, making front-end development fully controlled.   jquery is also an excellent foreground frame, with advantages of:  code simplicity, easy semantics, fast learning, and rich documentation.     jquery is a lightweight script with very small code and the latest version of the JavaScript package is only about 20K.     jquery supports CSS1-CSS3, as well as basic XPath.     jquery is Cross-browser, and it supports browsers including IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+.     can easily extend other features for jquery.     can completely separate the JS code and HTML code, easy to code and maintenance and modification.     Plug-ins are rich, in addition to the jquery itself with some special effects, you can implement more functions through plug-ins, such as form verification, tab navigation, drag and drop effects, table sorting, DataGrid, tree menu, image effects and Ajax upload.      In addition, there are prototype,bindows (JS framework)    Services, Zedgragh (. NET to do the statistical map, Spring,hibernate,structs,ejb,jbmp and other more famous
Discussion on the questions caused by NetEase JS-face Test
2012-02-05 23:58
First way:

var tt = ' AA ';
function Test () {
Alert (TT); underfined;
var tt = ' DD ';
Alert (TT); Dd
}
Test ();


The second way:

var myobject= {
Num:2,
Add:function () {
this.num=3;
(function () {
alert (this.num); underfined
this.num=4;
})();
Alert (this.num)//3
}
}

Myobject.add ();


This article is mainly about precompilation.

1. Undefined
When it is necessary to determine whether a variable is undefined, direct use
JS Code

1. alert (om = = undefined);

alert (om = = undefined);


There may be an error. Because JS if you reference undeclared variables, then there will be JS error, in the above example, if the OM did not declare, will report JS error. So judging a variable is undefined, preferably in this way
JS Code

1. alert (typeof om = = ' undefined ');

Alert (typeof om = = ' undefined ');



2. JS does not have a block scope, the variables declared in the function are available throughout the function (whether at the beginning of the function declaration or at the end), such as
JS Code

function () {
alert (OM); Show undefined
var om = ' abc ';
alert (OM); Show ABC
}



3. JS declares the variable of the entire function before the function executes, regardless of whether the declaration statement of the variable has a chance to execute, such as
JS Code

1. function () {
2. alert (OM); Show undefined
3. if (false) {
4. var om = ' abc '; There is no chance to execute this statement here
5.}
6.}

======================================================================

Today's job needs, search under JS interview questions, see a topic, about this
JS Code

<script>
var x = 1, y = z = 0;
function Add (n) {
n = n+1;
}

y = Add (x);

function Add (n) {
n = n + 3;
}

z = Add (x);
</script>



Q What is the value of x, Y, and Z after the execution is completed?

The person who looks at it immediately knows that X, Y and Z are 1, undefined and undefined respectively.

However, if you modify the two add functions, the title becomes
JS Code

<script>
var x = 1, y = z = 0;
function Add (n) {
return n = n+1;
}

y = Add (x);

function Add (n) {
return n = n + 3;
}

z = Add (x);
</script>


So what are Y and Z respectively? I immediately thought it was 2 and 4, but it turned out to be 4 and 4.
This means that the second add function already overwrites the first add function before the Add function is called the first time. Originally, this is the JS interpreter "precompiled", the JS parser executes the function declaration and the variable definition before executing the statement "precompiled", and this "precompilation" is not a page "precompiled", but a section of precompiled, the so-called segment is a <script> block. And look at the following code
JS Code


<script>
function Add (n) {
return n = n+1;
}
Alert (Add (1));
</script>

<script>
function Add (n) {
return n = n+3;
}
Alert (Add (1));
</script>



Will eject 2 and 4, respectively.

Then, change the above question again, as follows
JS Code

<script>
Alert (typeof AddA);
AddA ();
function AddA () {
Alert ("A executed!");
};
</script>
<script>
Alert (typeof Addb);
ADDB ();
var addb = function () {
Alert ("B executed!");
};
</script>



What is the result of the execution? According to the previous knowledge, the first <script> block executes normally, and the result is a dialog box that pops up "function" and "A executed!".
Then the second <script> block. The execution result is the pop-up "undefined" dialog box after the report JS error, said ADDB is not a function.
A little unexpected. Oh, in fact, the first script block in the AddA sentence is a function declaration, of course, "precompiled", but the second script block of the ADDB sentence is not a function declaration. It's just a "pre-declaration" of a variable prior to the execution of this <script>, so the first variable addb exists, but it's undefined (see Http://eclipse07.javaeye.com/admin/blogs /484566). So the results of the execution are as shown above.

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.