[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Very easy&quick Javascript question.

How to achieve this php method of adding more to the same variable in javascript?

$variable = ''
$variable.= '<h1>This is a header</h1>'
$variable.= '<p>This is a paragraph</p>' 

Open in new window


Thank in advance.
0
idusty
Asked:
idusty
  • 3
2 Solutions
 
mayank_joshiCommented:
you can use shorthand operator x += y

http://enacit1.epfl.ch/tutorials/JavaScript/expressions.html
0
 
mayank_joshiCommented:
var variable = ""
variable += "<h1>This is a header</h1>"
variable += "<p>This is a paragraph</p>"

Open in new window

0
 
iGottZFrontend EngineerCommented:
there are two ways.

one would be:
var foo = "Hello";
foo += " World!";

Open in new window


and the other one would be:

var foo = "Hello";
foo = foo.concat(" World!");

Open in new window


though the bottom one doesnt work in IE but would be faster.
0
 
mayank_joshiCommented:
sorry i missed  semi colon (;)

var variable = "";
    variable += "<h1>This is a header</h1>";
    variable += "<p>This is a paragraph</p>";

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now