Set two variables the same value on one line Apr26 '06
Just a quick tip that helped me out earlier today... Thought I’d document it, in case I forget.
I’ve always found it handy to, if possible, declare variables on the same line:
var myHouse, myCar;
var myHouse = "red", myCar = "blue";
However, what if two variables share the same value?
This is redundant:
var myHouse = "red", myCar = "red";
Rather, you can do this:
var myHouse = myCar = "red";
This works in JavaScript, and PHP - as far as I’ve tested. It may work in other languages, as well.
Categories: JavaScript
, PHP
, Programming
, Tips ![]()
Add Feedback (view all)
Leave feedback
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- Netflix set-top box still streams out-dated titles (3 recent visits)
- Standardized web page set-up (0 recent visits)
- JavaScript set selected on load (7251 recent visits)
- PHP – passing variables across pages (9470 recent visits)
- Create variables with a loop? (590 recent visits)
Stats
69 unique visits since August 2008
Recent Referrers (click)
- javascript, declaring two variables on the same line
- php set two variables same time
- php two var
- javascript value two variables
- javascript two variables
- javascript set two variables at same time
- variables that are the same
- php set variables to the same value
- javascript set two variables to the same value
- javascript set two variables to the same value
- javascript set two variables to the same value
- javascript set two variables to the same value
- PHP VARIABLES on the same line
- php two variables one value
- php two variables one value
- php two variables one value
- php if two variables are set
- javascript how to declare variable in one line
- php two variables into one
- same value to two variables in javascript