I am trying to concatenate variables in inside a function and then return. In php we just put a period before the \"=\" but it is not working in javascript.
Can someone
The +
operator will concatenate two strings, ie. "Hello" + " World" //> "Hello World". Using +=
is a short cut for assigning and concatenating a variable with its self.
ie. instead of:
var myVar = "somestring";
myVar = myVar + "another String";
you can just do:
var myVar = "somestring";
myVar += "another String";
For your problem:
function NewMenuItem() {
//This is just a small example. The end result is more broader then this
var output = "<input type='checkbox'> ";
output += "<input type='text'> ";
return output;
} //end of NewMenuItem(){
"+=" is the standard way to concatenate in javascript;
var a = "yourname";
var b = "yourlastname";
var name = a + b;
var complete_name = "my name is: ";
complete_name += name;
result : my name is: yourname yourlastname
With Concat
function or with plus operator (+)
.
Check this link jsfiddle to see a working example.