|
INTERVIEW QUESTIONS
WEB
JAVA SCRIPT
DETAILS
Question: How do I ... with JavaScript/JScript ... use the same variable name several times in a script?
Answer: By default all variables in JavaScript are global, meaning they retain their values everywhere in a scripted web page. To make a variable local to a block (such as a function), declare it with the keyword var. Here's a n example:
// here 'i' is a global counter variable that could, if reused // elsewhere in this script, create hard-to-find errors
for( i=1; i<=N; i++ ) { [code to iterate] }
// to ensure that 'i' exists only in the scope of this // counter, use var:
for( var i=1; i<=N; i++ ) { [ ... ] }
|
|
|
Category |
Java Script Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 7544 users |
Added on |
10/6/2012 4:50:23 AM |
Views |
72567 |
Rate it! |
|
|
Question:
How do I ... with JavaScript/JScript ... use the same variable name several times in a script?
Answer:
By default all variables in JavaScript are global, meaning they retain their values everywhere in a scripted web page. To make a variable local to a block (such as a function), declare it with the keyword var. Here's a n example:
// here 'i' is a global counter variable that could, if reused // elsewhere in this script, create hard-to-find errors
for( i=1; i<=N; i++ ) { [code to iterate] }
// to ensure that 'i' exists only in the scope of this // counter, use var:
for( var i=1; i<=N; i++ ) { [ ... ] } Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How do I ... with JavaScript/JScript ... embed JavaScript in a web page?
|
View Answer
|
|
How is JavaScript syntax like C / C++?
|
View Answer
|
|
How does JavaScript model the world?
|
View Answer
|
|
What are the language's basic entities?
|
View Answer
|
|
Where is the official bug list for JavaScript?
|
View Answer
|
|
Where can I find online documentation for JavaScript?
|
View Answer
|
|
What is JavaScript?
|
View Answer
|
|
How i will use email validation in java script, Like. User can't enter invalid email address?
|
View Answer
|
|
What is the main difference between Client side Java Script and and Server side Java Script how actully they run on both side with Example
|
View Answer
|
|
I do not want to go next field without filling the text? Whic function i should use. Phone No Text validation in javascript
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Java Script Interview Questions & Answers - Exam Mode /
Learning Mode
|