risk of javascript undefined variable

var objFiles = [{"name": "FileA"},{"name": "FileB"}];
var strHtml; //undefined

$.each(objFiles, function(i, v){
	strHtml += '<p>'+v.name+'</p>';
});
console.log(strHtml); //undefined<p>FileA</p><p>FileB</p>
var objFiles = [{"name": "FileA"},{"name": "FileB"}];
var strHtml  = '';

$.each(objFiles, function(i, v){
	strHtml += '<p>'+v.name+'</p>';
});
console.log(strHtml); //<p>FileA</p><p>FileB</p>

相关推荐