Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you "combine variables" in JavaScript to satisfy JSLint? [duplicate]

For a school project, I am trying to make a website that does stuff. To make it, I am using HTML, JavaScript, and CSS. I am using a compiler that gives debug hints. These hints are provided from JSLint. I am told that I should combine two of the variables that I have written, but I do not understand what this means.

I have done some research (on Stack Overflow and other websites), but all of these come up with people wanting to put variables into arrays.

Would anybody kindly explain to me what I should do?

The code (simplified):

var x = document.getElementById("some id");
var y = document.getElementById("some other id");
var z = document.getElementsByTagName("some tag name");

And JSLint says:

"Combine this with the previous 'var' statement: var y = document.getElementById("some other id");" and:

Combine this with the previous 'var' statement. var z = document.getElementsByTagName("some tag name");

Important Note: The code does work, but JSLint is telling me to fix it.

like image 521
Ooooh4 Avatar asked Aug 31 '15 14:08

Ooooh4


1 Answers

var x = document.getElementById("some id"),
    y = document.getElementById("some other id"),
    z = document.getElementsByTagName("some tag name");

You can declare variables like in the example above.

like image 171
mic4ael Avatar answered Sep 30 '22 04:09

mic4ael