面试题与答案
了解热门 JavaScript 面试题与答案,帮助应届生和有经验的候选人为求职面试做好准备。
面试前建议观看的最佳 LIVE 模拟面试
了解热门 JavaScript 面试题与答案,帮助应届生和有经验的候选人为求职面试做好准备。
面试题与答案
搜索问题以查看答案。
应届生 / 初级级别面试题与答案
How do you convert numbers between different bases in JavaScript?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What does isNaN function do?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What looping structures are there in JavaScript?
- for
- while
- do-while
- foreach
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What boolean operators does JavaScript support?
- &&
- ||
- !
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How do you create a new object in JavaScript?
- var obj = new Object();
- var obj = {};
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How about 2+5+"8"?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What does "1"+2+4 evaluate to?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What's a way to append a value to an array?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is negative infinity?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is this keyword?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is Javascript?
Scripts are embedded as plain text, interpreted by application.
Simpler execution model: don't need compiler or development environment.
Saves bandwidth: source code is downloaded, not compiled executable.
Platform-independence: code interpreted by any script-enabled browser.
But: slower than compiled code, not as powerful/full-featured.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is identifier in Javascript?
Starts with a letter, can contains digits & underscores
Case Sensitive!!
Should be meaningful to someone reading your code
Good: accountBalance, amountDue
Bad: bal, due,
Just plain wrong: 2bOrNotToBe, +var, total-value
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What type of variables are in Javascript?
Declare at the top of the program & terminate each statement with ;
Intialize variables when appropriate
Local variables (declared within a function) destroyed after function exit.
Can only be accessed within the function
Example Note Assignments
var candyBarPrice = 2.50;
var taxRate = .075;
var candyBarsPurchased;
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is Assignment Operator in Javascript?
subTotal = subTotal + 1.50
subTotal is assigned the value that is currently in subTotal plus the value of 1.50
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is Expression in Javascript?
Usually look like algebra formulas
total = subTotal * taxRate
Operators (+, -, *, /, etc.) have different levels of precedence, similar to algebra
Dont rely on it! For clarity, use parentheses.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Explain String in Javascript?
Hello World or Hello World
Variables can hold strings
var greeting = Hello World
String can be empty, i.e., contain no characters
var myAnswer =
Use \ (escape symbol) to type prohibited characters
\b for backspace, \n for newline, \t for tab, \ for double quote.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Few events in Javascript.
onclick - call when this button is clicked
onreset - call when the reset button is clicked
onload - call after page loads
onmouseover - call when mouse pointer enters image area
onmouseout - call when mouse pointer leaves image area
onfocus - call when control receives focus
onblur - call when a control loses focus
onchange - call when a control loses focus and the value of its contents has changed
onunload call when a page is closed
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Tell us about local variables.
local variable is visible only within the function body after its declared.
Commonly used to store results of an intermediate calculation.
function findMaxValue(num1, num2,num3) {
var tempMax; //local var
if (num1 >= num2) {
tempMax = num1;
}
else {
tempMax = num2;
}
if(num3 >= tempMax) {
tempMax = num3;
}
return tempMax;
} //end function
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Explain Global Variables in Javascript.
Global variables are visible from anywhere in the program, including inside functions
var globalHello = Hello!;
function writeHello() {
document.write(globalHello);
}
// outputs Hello!
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What are primitives in Javascript?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How do you submit a form using Javascript?
(0 refers to the index of the form if you have more than one form in a page, then the first one has the index 0, second has index 1 and so on).
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What does isNaN function do?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Methods GET and POST in HTML forms - what's the difference?
POST: Parameters are passed in the request body. There is no limit to the amount of data that can be transferred using POST. However, there are limits on the maximum amount of data that can be transferred in one name/value pair.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to get the contents of an input box using Javascript?
var myValue = window.document.getElementById("MyTextBox").value;
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to determine the state of a checkbox using Javascript?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to set the focus in an element using Javascript?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is the difference between an alert box and a confirmation box?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Can javascript code be broken in different lines?
that is ,
document.write("Hello \ world");
is possible but not document.write \
("hello world");
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
To put a "close window" link on a page?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to comment javascript code?
/*
*/ for block comments
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Name the numeric constants representing max,min values?
Number.MIN_VALUE
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What does javascript null mean?
It implies no object,or null string,no valid boolean value,no number and no array object.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to disable an HTML object?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
中级 / 1 到 5 年经验级别面试题与答案
How do you assign object properties?
- obj["age"] = 18
- obj.age = 18
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is Date class in Javascript? Please explain.
today = new Date(); // sets to current date & time
newYear = new Date(2002,0,1); //sets to Jan 1, 2002 12:00AM
methods include:
newYear.getYear() can access individual components of a date
newYear.getMonth()
newYear.getDay()
newYear.getHours()
newYear.getMinutes()
newYear.getSeconds()
newYear.getMilliseconds()
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What are Math routines in Javascript?
Math.sqrt
Math.pow
Math.abs
Math.max
Math.min
Math.floor
Math.ceil
Math.round
Math.PI
Math.E
Math.random function returns number in [0..1)
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What about Navigator object?
navigator.appVersion property that gives the browser version.
navigator.userAgent property that gives the browser related information.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Explain String functions in Javascript.
encapsulates data (properties) and operations on that data (methods)
a String encapsulates a sequence of characters, enclosed in quotes
properties include
length : stores the number of characters in the string
methods include
charAt(index) : returns the character stored at the given index
(as in C++/Java, indices start at 0)
substring(start, end) : returns the part of the string between the start
(inclusive) and end (exclusive) indices
toUpperCase() : returns copy of string with letters uppercase
toLowerCase() : returns copy of string with letters lowercase
to create a string, assign using new or just make a direct assignment (new is implicit)
word = new String("foo"); word = "foo";
properties/methods are called exactly as in C++/Java
word.length word.charAt(0)
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How do we get JavaScript onto a web page?
You can directly add a script element inside the body of page.
1. For example, to add the "last updated line" to your pages, In your page text, add the following:
<p>blah, blah, blah, blah, blah.</p>
<script type="text/javascript" >
<!-- Hiding from old browsers
document.write("Last Updated:" +
document.lastModified);
document.close();
// -->
</script>
<p>yada, yada, yada.</p>
(Note: the first comment, "<--" hides the content of the script from browsers that don't understand javascript. The "// -->" finishes the comment. The "//" tells javascript that this is a comment so javascript doesn't try to interpret the "-->". If your audience has much older browsers, you should put this comments inside your javascript. If most of your audience has newer browsers, the comments can be omitted. For brevity, in most examples here the comments are not shown. )
The above code will look like this on Javascript enabled browsers,
2. Javascript can be placed inside the element
Functions and global variables typically reside inside the <head> element.
<head>
<title>Default Test Page</title>
<script language="JavaScript" type="text/javascript">
var myVar = "";
function timer(){setTimeout('restart()',10);}
document.onload=timer();
</script>
</head>
Javascript can be referenced from a separate file
Javascript may also a placed in a separate file on the server and referenced from an HTML page. (Don't use the shorthand ending <script ... />). These are typically placed in the <head> element.
<script type="text/javascript" SRC="myStuff.js"></script>
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How can JavaScript make a Web site easier to use? That is, are there certain JavaScript techniques that make it easier for people to use a Web site?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to create arrays in JavaScript?
var scripts = new Array();
We can add elements to this array like this
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
Now our array scrips has 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2 . Here is the way to get the third element of an array.
document.write(scripts[2]);
We also can create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to set a HTML document's background color?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
How to write a script for "Select" lists using javascript?
mySelectObject.options[3] = null;
2. To truncate a list set its length to the maximum size you desire
mySelectObject.length = 2;
3. To delete all options in a select object set the length to 0.
mySelectObject.length
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Is a Javascript script faster than an ASP script?
computation,so it is always faster than any server-side script like ASP,PHP,etc..
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is a prompt box?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
资深 / 专家级别面试题与答案
What's relationship between JavaScript and ECMAScript?
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Write a javascript to get difference between two dates.
newYear = new Date(2004,0,1);
secs = Math.round((now-newYear)/1000);
days = Math.floor(secs / 86400);
secs = days*86400;
hours = Math.floor(secs / 3600);
secs = hours*3600;
minutes = Math.floor(secs / 60);
secs = minutes*60
document.write(days + " days, " +
hours + " hours, " +
minutes + " minutes, and " +
secs + " seconds.");
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What is User-Defined class in Javascript?
simply define a function that serves as a constructor
specify data fields & methods using this
no data hiding: can't protect data or methods
function Die(sides)
{
this.numSides = sides;
this.numRolls = 0;
this.Roll = Roll;
}
function Roll()
{
this.numRolls++;
return Math.floor(Math.random()*this.numSides) + 1;
}
die6 = new Die(6);
die8 = new Die(8);
roll6 = -1; // dummy value to start loop
roll8 = -2; // dummy value to start loop
while (roll6 != roll8) {
roll6 = die6.Roll();
roll8 = die8.Roll();
document.write("6-sided: " + roll6 +
" " +
"8-sided: " + roll8 + "
");
}
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Where are cookies actually stored on the hard disk?
In the case of Netscape with Windows OS,all the cookies are stored in a single file called
cookies.txt
c:\Program Files\Netscape\Users\username\cookies.txt
In the case of IE,each cookie is stored in a separate file namely username@website.txt.
c:\Windows\Cookies\username@Website.txt
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
Are you concerned that older browsers don't support JavaScript and thus exclude a set of Web users or individual users?
The situation makes scripting a challenge, especially for newcomers who may not be aware of the limitations of earlier browsers. A lot of effort in my books and ancillary material goes toward helping scripters know what features work in which browsers and how to either workaround limitations in earlier browsers or raise the compatibility common denominator.
Designing scripts for a Web site requires making some hard decisions about if, when, and how to implement the advantages scripting offers a page to your audience. For public Web sites, I recommend using scripting in an additive way: let sufficient content stand on its own, but let scriptable browser users receive an enhanced experience, preferably with the same HTML document.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
What does the "Access is Denied" IE error mean?
A javascript in one window or frame is tries to access another window or frame whose document's domain is different from the document containing the script.
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。