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
- Social networking: say it; don't spray it
Similar Entries
- Netflix set-top box still streams out-dated titles (3 recent visits)
- Standardized web page set-up (1 recent visits)
- JavaScript set selected on load (8876 recent visits)
- PHP – passing variables across pages (11831 recent visits)
- Create variables with a loop? (739 recent visits)
Stats
92 unique visits since August 2008
Recent Referrers (click)
- javscript set variable in one line
- change two variables in one line+javascript
- php two variables on one line
- inputting 2 variables on one line
- declare and set a variable in one line in javascript
- php set 2 variables in the address
- php set 2 variables in the address
- set two variables php
- php two variables same
- php two variables same value
- set 2 variable javascript
- set two variable at the same time javascript
- php two variables one input
- two of the same variable
- javascript set many variables to same value
- two variables in a set
- declare two variables in one javascript
- setting two variables to the same value php
- javascript 2 variables in 1 value
- php set vars to same value