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.
- No more iPod and iTunes for me
- Keyboard shortcut for my blog
- Pownce acquired by Six Apart: critics aflame
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 (7442 recent visits)
- PHP – passing variables across pages (9721 recent visits)
- Create variables with a loop? (601 recent visits)
Stats
72 unique visits since August 2008
Recent Referrers (click)
- javascript write 2 variables in same line
- change value of two variable
- php set many variables on one line
- 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