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

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

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.

Contact Matt

Similar Entries

Stats

72 unique visits since August 2008

Syndicate

Advertisements