Var 1 « Var « Javascript Data Type Q&A

Home
Javascript Data Type Q&A
1.Array
2.Clojure
3.date
4.decimal
5.function
6.global
7.loop
8.math
9.number
10.object
11.Regular Expression
12.scope
13.String
14.Var
15.variable
Javascript Data Type Q&A » Var » Var 1 

1. Javascript: var map = {}; var list = [];    stackoverflow.com

Can someone tell me what exactly the two above lines of javascript do? And more importantly, what it's called so I can search some javascript references to learn about it? I ...

2. ie8 var w= window.open() - "Message: Invalid argument."    stackoverflow.com

I have a site that has an IE8-only problem: The code is:

var w = window.open(urlstring, wname, wfeatures, 'false');
The error is:
Message: Invalid argument.
Line: 419 Char: ...

3. IE error when trying for( var i in window.external )    stackoverflow.com

I am building an object/property dump using JavaScript. This code breaks under Internet Explorer 8 (assuming subject = window.external)

// Gather the property names into the keys array.
var keys = Array(); for( ...

4. how to add a var to href    stackoverflow.com

well what is needed is something like
var link = " http://www.google.com"; < a href= 'link' /> or something like it . so i need to use ...

5. JavaScript: If var statements are executed first, then why does this not work?    stackoverflow.com

I tried the following in JavaScript (Firefox 3.5, Windows XP):

(function(){
    window.foobar = 'Welcome!';
})();

var foobar = 'PWN3D!';

alert(foobar);
The output was 'PWN3D!'. Why did my code PWN me? I thought var ...

6. var undefined = true;    stackoverflow.com

I'm doing some experimenting with this malicious JavaScript line: var undefined = true; Every uninitialized variable in JavaScript has the value of undefined which is just a variable that holds the special ...

7. Is there a way to check if a var is using setInterval()?    stackoverflow.com

For instance, I am setting an interval like

timer = setInterval(fncName, 1000);
and if i go and do
clearInterval(timer);
it does clear the interval but is there a way to check that it cleared the ...

8. How can i define more than one var in one step?    stackoverflow.com

is there a good solution how can i define more than one var with the same value in one step an the beginning of my funcion?

function myFunction (){
   var ...

9. Var is not defined but why?    stackoverflow.com

i have a little problem with Codemirror (http://codemirror.net/manual.html) My code

$(document).ready(function ust()
    {    
        pa_textareas();

    });


  ...

10. Confusing JavaScript statement: "var x = new this();"    stackoverflow.com

I thought I understood the concept of the JavaScript prototype object, as well as [[proto]] until I saw a few posts regarding class inheritance. Firstly, "JavaScript OOP - the smart way" at ...

11. Why can I do 'if (a = 7) ...' but not 'if (var a = 7) ...'?    stackoverflow.com

Title says it all. Why does

if (prev = this.Prev()) {
    ...
}
work but
if (var prev = this.Prev()) {
    ...
}
does not? this.Prev() is a method ...

12. JavaScript class - trouble accessing public var in private method    stackoverflow.com

Seems like a simple problem, but can't get this to work. In the example below, unselect is called but the public variable 'this.backSelected' is undefined. If I move the code of the ...

13. What does var x = x || {} ;    stackoverflow.com

what does the following code do in java script:

var x = x || {};

14. So confused about why vars work sometimes with or without var?    stackoverflow.com

I am really confused as to why sometimes vars will not work when "var" is declared in front of them when used in a namespaced object. Isn't adding "var" in front ...

15. How can I get a JavaScript VAR with ExternalInterface?    stackoverflow.com

I am trying to use the ExternalInterface.call function in my ActionScript(2.0) to get a javascript var value set in the wrapping document. The following seems to work in FireFox and in ...

16. javascript problem: var a="1";b={a:a},the b variant isn't {"1":1}    stackoverflow.com

 var a="1";
 b={a:a},
the b variant isn't {"1":1},why will this happened? also want to know if i want to get the result what i want ,how can i solve this problem

17. What is this in javascript: "var var1 = var1 || []"    stackoverflow.com

I just want to increase my core javascript knowledge. Sometimes I see this statement but I don't know what it does:

var var1 = var1 || [];
What does it means and/or what's it ...

18. var foo = foo || alert(foo);    stackoverflow.com

Can someone explain what this does?

var foo = foo || alert(foo);

19. var something = somethingElse.obj = somethingElse.obj || {} - what is this used for?    stackoverflow.com

Sorry about the odd title... not sure how else to enquire about a language feature like this. I was reading about module patterns when i came across this example when ...

20. Is it inefficient to redeclare var x = obj.prop for the sake of compactness?    stackoverflow.com

I was wondering what people thought of doing something like

var x = obj.child.prop1;
doSomething(x);
doOtherThings(x);
Doesn't var allocate more memory, rather than create a reference? Would it be worth it to avoid redefining x ...

21. limit digits in var multiplication total    stackoverflow.com

I have this: var ivu = (total3); document.getElementById("project_pay_total_field4").value = "$" + total3 * 0.07 ; The multiplication produces this: $10.080000000000002 --Its too long and when done in regular calculator it only says 10.08; ...

22. how to check if text exists in javascript var    stackoverflow.com

I have a var that contains some text. I would like to check whether the texts has a certain word. Example:

var myString = 'This is some random text';
I would like ...

23. JavaScript: Testing for undefined throws var is not defined error...?    stackoverflow.com

This is an oddity I've seen occasionally in JS - maybe someone can shed light on it. I do a test for undefined on a variable:

if (x !== 'undefined'){}
or even
if (typeof x ...

24. Js - if var is undefinied    stackoverflow.com

Why doesn't an alert show in the below code?

var a = Array();
a[1] = "asd";
a[100] = "asdd";
alert(typeof a[50]);
if(typeof a[50] === 'undefinied') alert('und');

25. in javascript whay use " var that = this "    stackoverflow.com

hi i am new with javascript What is the benefit of using this line var that = this An example

function Person( firstname, lastname, age ) {

this.firstname = firstname;

this.lastname = lastname;

this.age = age;

getfullname = function() ...

26. in javascript why use " var that = this "    stackoverflow.com

hi i am new with javascript What is the benefit of using this line var that = this An example

function Person( firstname, lastname, age ) {

    this.firstname = firstname;

   ...

27. Access DOM of a TR in a var    stackoverflow.com

I'm cloning some table rows and would like to increment the IDs of its child nodes, I've tried doing this by:

var rowID = document.getElementById('RowTbl').rows.length / 2;
 var NameRowCopy= document.getElementById('NameRow' + rowID).cloneNode(true);
 ...

28. When to use var in Javascript    stackoverflow.com

Maybe pretty easy question. Where should I use var keyword in JavaScript. It seems to me using it or not have the same effect ( but of course I'm still learning ...

29. how to check if var is not empty with javascript?    stackoverflow.com

Not having much luck with this. I'm trying to determine if a var is not empty.

$('#content').mouseup(function() {

    var selection = getSelected();

    if ...

30. Can someone decode this javascript?    stackoverflow.com

I found this javascript in a Facebook viral page here. I think the code is malicious so I would like to know what it does. Here is the code:

javascript: var ...

31. Why is it illegal to have var inside an if() expression in javascript?    stackoverflow.com

At least in V8 something like

if((var i = x*x) == 2){}
will give an error about an unexpected 'var' keyword. However there is no error if the var happens before the if() ...

32. How to set a javascript var as undefined    stackoverflow.com

Given:

console.log(boo); this outputs undefined
Given:
var boo = 1;
console.log(boo); this outputs 1
After defining boo and setting to 1, how can I then reset boo, so that console.log outputs undefined? Thanks

33. Is there anything wrong with using 'var undefined' to test for undefined    stackoverflow.com

Is there anything wrong with this test for undefined?

var undefined;

if(x == undefined){
    //do something
}
or this:
function undefined(x){
    return typeof x == 'undefined';
}

if(undefined(x)){
    //do ...

34. When do I use var?    stackoverflow.com

My understanding it that with in a function if I use var then I have a local variable. If I do not delcare var I now have a global variable. But ...

35. Javascript shim to redefine "const" as "var" for Internet Explorer    stackoverflow.com

Internet Explorer doesn't support the "const" keyword. Can I use a shim that checks if "const" is supported and, if not, redefines it as var? I guess it would be nice ...

36. Why is for (var i = 100; i--;) {} so much slower (70%) than for (var i = 100; i-->0;) {} in Firefox?    stackoverflow.com

Here's the test: http://jsperf.com/forloopspeed As you can see, the difference is huge in Firefox, present to a much lesser extent in Safari, and absent in Chrome and Opera. The analogous ...

37. When is the "var" need in js?    stackoverflow.com

Possible Duplicate:
Difference between using var and not using var in JavaScript
sometime, I saw people doing this
for(var i=0; i< array.length; i++){
 //bababa

}
but I also see ...

38. Way to see invisible entities in var (ex. \n)    stackoverflow.com

I just had a var I believed to be equal to "" or undefined. It turned out it was equal to \r. I couldn't see this until I wrapped the var ...

39. Problems to get a dynamic var in javascript - eval()    stackoverflow.com

I have a simple problem to solve, I know how to do it in PHP but have no ideia how to do it in javascript. I gave a dinamic form, with N ...

40. javascript var alerts but when used is undefined    stackoverflow.com

This is weird. Check this out:

 for( var i = 0; i <= videos.length; i ++ ){

    alert(videos[i].id); // this works and alerts the correct number

   ...

41. emacs: how to get js-mode to properly indent continued (compound?) var declarations?    stackoverflow.com

If I use distinct var statements like this:

function stretchDiv(){
    var wh = $(window).height();
    var sz2 = wh - ((paddingTop + paddingBottom) + (mainTop + ...

42. javascript - what kind of thing in a var    stackoverflow.com

I've got either a literal object or one of it's components in var Z. Ie. one of the following

var Q = {"name" : 123};

Z = Q; 
Z = Q["name"];
how can ...

43. change style of using getElementsByTagName textAlign from center to left    stackoverflow.com

I have a script to change the text alignment for the textarea with the id textbox1 below:

 // <![CDATA[
 function alignFix() {

 document.getElementById("textbox1").style.textAlign="left";

 }
 // ]]>
Here's the ...

44. Javascript : var 3po = true;?    stackoverflow.com

I read some where else that following is illegal

var 3po = true;
but
var highNoon = false;
is legal. Could someone explain what is all this means? Why the first statement is illegal while ...

45. How to assign backgroundColor to a var in JavaScript    stackoverflow.com

seems like a simple question but I don't know JavaScript too well and my search-fu is turning up nothing relevant. I need to set the backgroundColor property of a textbox to a ...

46. What does "var" do in JavaScript? Why is it sometimes part of an assignment?    stackoverflow.com

Possible Duplicate:
Difference between using var and not using var in JavaScript
var foo = 1;

foo = 1;
What is the difference between above two lines ? ...

47. How do I set up "var count" so that it is initialized the first time and then incremented?    stackoverflow.com

I tried this:

var count;

function testCount ()
{
  if (count)
  {
    alert("count is: " + count);
    count++;
  }    
 ...

48. why does apply only take one param in this case?    stackoverflow.com

I'm studying apply and I am trying to understand why the code I am studying only passes one parameter to apply. I first define Quo:

var Quo = function(string) {
  ...

49. Trouble using selectedIndex as a var    codingforums.com

I am getting an error: "document.getElementById("gender") is null" Any ideas how I can get this to work? Code: change var fruit to banana
change var fruit to grape
change var fruit to orange

61. HELP Var not working    codingforums.com

62. Parent Window Var Problem    codingforums.com

Hi, I am trying to get a html page to open a new (but small) window with no tool bars or status bar ect. On the new window will be two buttons Yes and No. With in the original page is a javascript timer set to 30 mins. the number of mins has its own var X. What i want to ...

63. JavaScript SEARCH on var    bytes.com

64. Not picking the enddate var    bytes.com

65. for (var i in obj) question    bytes.com

66. weird var problem    bytes.com

Hi everyone, I have encountered a small problem concerning global variables: var print = function(string){ var reference = document.getElementById("myDiv"); reference.innerHTML += string + "
"; }; This doesn't: REF = { div1 : document.getElementById("myDiv") }; var print = function(string){ REF.div1.innerHTML += string + "
"; }; Firebug complains that REF.div1.innerHTML is null . Why?

67. response.write seen as var    forums.digitalpoint.com

In this code the response.write (in red) returns "response undefined", I suppose it is being interpreted as a var. I have been staring at this code for hours and probably have gone a little "code blind". Can anyone spot the problem? Code:

Income 
Income Band
...

78. Pass a var to func from onload    forums.devshed.com

79. Simple problem passing a var    forums.devshed.com

You cannot do this. Why? Because your variable is a javascript variable meaning it can only be accessed through javascript (or AJAX?). The are the specified code (javascript in your case). This can be done using a server side language ...

80. Var and assign    forums.devshed.com

81. Pass var thru