Basic JavaScript interview questions

Source: Internet
Author: User
Tags javascript array

1. typeof (NAN), typeof (infinity), typeof (null), typeof (undefined)
2. Nan = Nan
3. Nan! = Nan
4. Nan> = Nan
5. null = undefined
6. null> = undefined
7. null <= undefined
8. parseint ("123abc ")
9. "123abc"-0
10. Infinity> 10
11. Infinity> "ABC"
12. Infinity = Nan
13. True = 1
14. New String ("ABC") = "ABC"
15. New String ("ABC") = "ABC"

Output results

1,
VaR A = "123abc ";
Alert (typeof (A ++ ));
Alert ();

2,
VaR A = "123abc ";
A. valueof = function () {return parseint ();}
Alert (++ );
Alert (a-0 );

3,
VaR A = new object ();
A. tostring = function () {return "123abc ";}
A. valueof = function () {return parseint ();}
Alert (++ );
Alert (a-0 );

4,
String. Prototype. valueof = function ()
{
Return parsefloat (this );
}
Alert ("123abc"> 122 );
Alert (new string ("Fig")> 122 );

5,
VaR S = new string ("ABC ");
Alert (typeof (S) = typeof ("ABC "));
Alert (S = "ABC ");
Alert (S. tostring () = s );

6,
VaR A = new object ();
A. tostring = function () {return ""};
VaR B = new object ();
B. tostring = function () {return "B "};
Alert (A> B );
A. valueof = function () {return 1 };
B. valueof = function () {return 0 };
Alert (A> B );

7,
Function step ()
{
Return function (X)
{
Return x + A ++;
}
}
VaR A = step (10 );
VaR B = step (20 );
Alert (A (10 ));
Alert (B (10 ));

 

Question 1
VaR I = 5;
Function fo ()
{
VaR I = 4;
VaR Fi = new function ("alert (I );");
FI ();
}
Fo ();

Question 2
Function F1 ()
{
I = 20;
Eval ("Var I ");
}
Alert (I );
Function F1 ()
{
I = 10;
VaR I;
}
Alert (I );

Question 3
Function F1 ()
{
Alert ("1 ");
}
Function F2 ()
{
Alert ("2 ");
}
VaR F3 = f1.call;
F3.call (F2 );

Question 4
Function fo ()
{
VaR I = 0;
Return function (N)
{
Return N + I ++;
}
}
Fo () (15 );
Alert (fo () (20 ));

Question 5
Function F1 (N)
{
If (n = 0) return;
Else return F2 (-- N );
}
Function F2 (N)
{
Alert (f1.caller );
Return F1 (N );
}
F1 (2 );

Question 6
Alert (typeof function. Prototype );
Alert (object. Prototype instanceof function );
Alert (function. Prototype instanceof function );

Prototype and Object

Question 1
Function cls1 ()
{
This. A = new array;
}
Function cls2 ()
{
}
Cls2.prototype = new cls1;
VaR x = new cls2;
Var y = new cls2;
X. A. Push (1, 2, 3 );
Alert (Y. );

Question 2
Function cls1 ()
{
This. A = 1;
}
Function cls2 ()
{
}
VaR x = new cls2;
Cls2.prototype = new cls1;
Var y = new cls2;
Alert (X. );
Alert (Y. );

Question 3
Function cls1 ()
{
This. A = 1;
}
Function cls2 ()
{
}
VaR x = new cls2;
Cls2.prototype. A = 1;
Var y = new cls2;
Alert (X. );
Alert (Y. );

Question 4
Function cls1 ()
{
This. A = 1;
}
Function cls2 ()
{
}
VaR x = new cls2;
Cls2.prototype. A = 1;
Var y = new cls2;
Alert (X. );
Alert (Y. );

Question 5
String. Prototype. Self = function ()
{
Return this;
}
VaR S = "S ";
Alert ("S". Self () = "S ")
Alert (S. Self () = s)
Alert ("S" = "S ")
Alert ("S". Self () = "S". Self ())
Alert (S. Self () = S. Self ())

 

Enter the Javascript interview questions of Famous Enterprises
Basic
1. brief answer to the following questions:
1.1 What are the differences between the two variables of JScript?
1.2 list three main data types of JScript, two composite data types, and two special data types.
1.3 methods for capturing exceptions in the program.
2. Declare and initialize a string array and store ten Chinese Characters in uppercase.

3. Write the running result of the following routine.
3.1 What is K equal to after the program runs?
1
2
3
For (I = 0, j = 0; I & lt; 10, J & lt; 6; I ++, J ++ ){
K = I + J;
}

3.2 write the returned results of the datedemo function. 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 );
 
}

3.3 write the value of the result variable after the last statement of the program is executed.

VaR Epsilon = 0.00000000001; // small numbers to be tested.
 
Function integercheck (A, B, C)
 
{
 
If (A * A) = (B * B) + (C * C )))

Return true;
 
Return false;
 
}
 
Function floatcheck (A, B, C)
 
{
 
VaR Delta = (A * A)-(B * B) + (C * C )))
 
Delta = math. Abs (DELTA );
 
If (delta & lt; epsilon)
 
Return true;
 
Return false;
 
}
 
Function checktriplet (A, B, C)
 
{
 
VaR D = 0;
 
If (B & gt;)
 
{
 
D =;
 
A = B;
 
B = D;
 
}
 
If (C & gt;)
 
{
 
D =;
 
A = C;
 
C = D;
 
}
 
If (a % 1) = 0) & amp; (B % 1) = 0) & amp; (C % 1) = 0 ))
 
{
 
Return integercheck (A, B, C );
 
}
 
Else
 
{
 
Return floatcheck (A, B, C );
 
}
 
}
 
// The following three statements are assigned to the sample value for testing.

VaR sidea = 5;
 
VaR sideb = 5;
 
VaR sidec = math. SQRT (50.001 );
 
VaR result = checktriplet (sidea, sideb, sidec );

4. Write a function to return the start and end positions of each word and its characters in a specified English sentence.
Example: "The rain in Spain falls mainly in the plain ."
Return "The 0-3", "Rain 4-8", and so on "... ... "Plain 38-43"
Advanced
5 What is the order in which the browser interprets the JScript?
6. Determine whether the following expressions are true or false.

100 "= 100;
False = 0;
"100" = 100;
False = 0;
7. How to set the default object for a statement (usually used to shorten the amount of code that must be written in a specific situation and make the code shorter and easier to read )? In the following example, pay attention to the reuse of Math:
1
2
3
X = math. Cos (3 * Math. Pi) + math. Sin (math. ln10)
 
Y = math. Tan (14 * Math. e)

8. If the number of attributes of an object is unknown, how does one traverse the attributes of the object?
9 Write a regular expression that matches HTML tags
10. Construct a custom object to realize the objectization of a rectangle. Requirements:

A) ID describing the rectangle (name)
B) color of the rectangle)
C) Describe the width (width) of the rectangle)
D) Describe the height of the rectangle)
E) getarea ())
F) write the complete code of the constructor.
G) Code of the called instance

 

Javascript interview questions

Javascript pop-up confirmation box function
After the text box is entered, press enter to jump to the next text box
How to write the message box prompted for deletion on the server

What types of input are in form? What are their respective operations?
Text radio checkbox file button image submit reset hidden

2. What are the roles of colspan and rowspan in the border and cellpadding TD labels in Table labels?
Border Boundary
Cellpadding margin
Colspan
Rowspan

3. You can set readonly and disable for input in form. What are the differences between the two attributes?
Readonly cannot be edited, but can be selected and copied.
Disable cannot edit copy Selection

4. What are the three pop-up message reminders (warning window, confirmation window, and Information Input window) commands in JS?
Alert
Confirm
Prompt

Which of the following statements produces a running error :()
A. var OBJ = ();
B. var OBJ = [];
C. var OBJ = {};
D. var OBJ = //;
2. Which of the following words does not belong to a reserved JavaScript word :()
A.
B. Parent
C. Class
D. Void
3. Select a true expression :()
A. null instanceof object
B. null === undefined
C. null = undefined
D. Nan = Nan
Ii. multiple choice questions
4. incorrect understanding of javascript :()
A. JScript is short for Javascript
B. Javascript is a Java scripting language developed by Netscape. It aims to simplify Java development.
C. There are a lot of compatibility problems between Firefox and IE mainly because they have different support for JavaScript.
D. Javascript must be used for Ajax technology
5. If the foo object has the ATT attribute, which of the following methods can be used to obtain the value of the ATT attribute :()
A. Foo. ATT
B. Foo ("ATT ")
C. Foo ["ATT"]
D. Foo {"ATT "}
E. Foo ["A" + "T" + "T"]
6. Which HTML tags can manually input text without specifying special attributes :()
A. <textarea> </textarea>
B. <input type = "text"/>
C. <input type = "hidden"/>
D. <div> </div>
7. Which of the following are global functions of JavaScript :()
A. Escape
B. parsefloat
C. Eval
D. setTimeout
E. Alert
8. Which of the following statements about IFRAME are true :()
A. Through IFRAME, the webpage can embed other webpage content and can be changed dynamically
B. Embedded IFRAME can be used to obtain the object of the outer webpage under the same domain name.
C. Under the same domain name, the outer webpage script can obtain the objects in the IFRAME webpage.
D. You can use a script to adjust the IFRAME size.
9. Which of the following statements about the table are true :()
A. the table can contain tbody elements.
B. the table can contain the caption element.
C. The table can contain multiple tbody elements.
D. The table can contain colgroup elements.
E. The table can contain the col element.
10. Which of the following statements about the window object of IE are true :()
A. Window. Opener attributes itself point to window objects
B. The window. Reload () method can be used to refresh the current page.
C.window.location”a.html#and zookeeper location.href?a.html=the front page is replaced with an a.html page.
D. defines the global variable G. You can use window. g to access this variable.
Iii. Q &:
1. about the use of the Javascript array sorting method sort (), focusing on the use of the sort () parameter and its internal mechanism
2. Briefly describe the differences between DIV elements and span elements.
3. Combine the <span id = "outer"> <span id = "inner"> text </span> structure to discuss the differences between innerhtml outerhtml innertext.
4. Description of several XHTML specifications (at least 3)
5. What are the related knowledge about Web standardization (or website reconstruction) and how many web standards do you know?
Iv. Program questions:
1. Complete the content of the Foo () function. A dialog box is displayed, prompting which of the following single orders are selected.
<HTML>
<Body>
<SCRIPT>
Function Foo (){
// Add code here
Return false;
}
</SCRIPT>
<Body>
<Form name = "form1">
<Input type = "radio" name = "radiogroup"/>
<Input type = "radio" name = "radiogroup"/>
<Input type = "radio" name = "radiogroup"/>
<Input type = "radio" name = "radiogroup"/>
<Input type = "radio" name = "radiogroup"/>
<Input type = "radio" name = "radiogroup"/>
<Input type = "Submit"/>
</Form>
</Body>
</Html>
2. Fill in the function body of the annotation part to bring up the "successful" dialog box for Foo () function call. The Code should be as short as possible.
<HTML>
<Body>
<SCRIPT>
Function Foo (){
VaR STR = reverse ('a, B, c, d, e, f, G ');
Alert (STR );
If (STR = 'G, F, E, D, C, B, A') Alert ('success ');
Else alert ('failed ');
}
Function reverse (STR ){
// Add code here to complete the string flip Function
}

 
<SCRIPT type = "text/JavaScript">
VaR x = 1;
Var y = 0;
VaR z = 0;
Function add (n) {n = n + 1 ;}
Y = add (X );
Function add (n) {n = N + 3 ;}
Z = add (X );
S = Y + z;
</SCRIPT>

Please:
What is the value of Y?
What is the Z value?
What is the value of S?

I believe that some students will certainly give a wrong answer. Of course, they don't mean they don't, but they may be too keen!

First, let's take a look at function Add. Neither of them has a return value, but we know that if there is no clear return value, all return undefined. Therefore, both Y and Z will be undefined, then s will naturally not be a number. Yes, s should be Nan.

What if we change the question? As follows:
<SCRIPT type = "text/JavaScript">
VaR x = 1;
Var y = 0;
VaR z = 0;
Function add (n) {return n = n + 1 ;}
Y = add (X );
Function add (n) {return n = N + 3 ;}
Z = add (X );
S = Y + z;
</SCRIPT>

There are return values for both function add operations. What are the values of Y, Z, and s?
Yes, Y and Z are both 4, and S is 8. Why is y not 2 but 4? Because in Javascript, the function declared directly through the function, which is defined later, will affect the previous reference, as follows:

<SCRIPT type = "text/JavaScript">
Function x () {alert (2 )};
X (); // output 3
Function x () {alert (3 )};
X (); // output 3
</SCRIPT>

What will happen if the function is declared through var? Let's take a look:

<SCRIPT type = "text/JavaScript">
VaR x = function () {alert (0 )};
X (); // output 0
VaR x = function () {alert (1 )};
X (); // output 1
X (); // output 1
</SCRIPT>

The function defined later through var does not affect the previous reference.

What happens if the two modes are mixed?

<SCRIPT type = "text/JavaScript">
Function x () {alert (2 )};
X (); // output 3
VaR x = function () {alert (0 )};
X (); // output 0
VaR x = function () {alert (1 )};
X (); // output 1
Function x () {alert (3 )};
X (); // output 1
</SCRIPT>

The result is like this. Have you guessed it?

The function defined by function affects the previous reference, but it cannot change the reference after the function is declared by var. Instead, the function is declared by var, changed the reference after declaring the function through the function.

Therefore, if:
<SCRIPT type = "text/JavaScript">
VaR x = function () {alert (1 )};
X ();
Function x () {alert (3 )};
X ();
</SCRIPT>
The following X () is also 1.

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.

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.