473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

static variable in javascript

Hello Everyone!

I am trying to declare a static variable in javascript (i.e) the variable should remember its value after coming out of the function.

i hav tried as below:

Expand|Select|Wrap|Line Numbers
  1. static i = 0;
  2. alert(i);
Expand|Select|Wrap|Line Numbers
  1. static int i=0;
  2. alert(i);
Expand|Select|Wrap|Line Numbers
  1. var i=0;
  2. alert(i);
Expand|Select|Wrap|Line Numbers
  1. static var i=0;
  2. alert(i);
but all the above codes or not working
can anybody tell me how?
May 8 '07 #1
1 3906
sumittyagi
202 Expert 100+
Hello Everyone!

I am trying to declare a static variable in javascript (i.e) the variable should remember its value after coming out of the function.

i hav tried as below:

Expand|Select|Wrap|Line Numbers
  1. static i = 0;
  2. alert(i);
Expand|Select|Wrap|Line Numbers
  1. static int i=0;
  2. alert(i);
Expand|Select|Wrap|Line Numbers
  1. var i=0;
  2. alert(i);
Expand|Select|Wrap|Line Numbers
  1. static var i=0;
  2. alert(i);
but all the above codes or not working
can anybody tell me how?
There's nothing like static variables in javascript.
javascript is not java.

if you want to have value of a variable out of the fucntion, then simply keep a global variable.
variables can be defined by var keyword only.
May 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: lkrubner | last post by:
I'm offering users the ability to type weblog posts into a form and post them. They type the text into a TEXTAREA which is on a form. The form, when submitted, hits a PHP script. Before it is...
5
by: seans | last post by:
Hi, Is there a way to create a static variable in Javascript? I want to use a recursive function to traverse a DOM tree and examine each node. If the node is a text object I would like to save...
9
by: AnandRaj | last post by:
Hi guys, I have a few doubts in C. 1. Why static declartions are not allowed inside structs? eg struct a { static int i; }; Throws an error ..
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
7
by: jab3 | last post by:
Does JavaScript have "static" variables. That is, as in C (or local in Perl)? How can I keep a variable in a JavaScript function that doesn't change from call to call? It may not make sense in...
6
by: Vladislav Kosev | last post by:
I have this strange problem now twice: I am writing this relatevely large web site on 2.0 and I made a static class, which I use for url encoding and deconding (for remapping purposes). This static...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.