如何在JS中检查哪个var是正确的?

时间:2016-04-14 08:03:41

标签: javascript



var first_name = "Shaunak";
var lastName = "Gujjewar";
document.getElementById("demo").innerHTML = first_name;
document.getElementById("demo").innerHTML = lastName;

<h1><tt>JS is case sensitive.</tt></h1>
<p>
  JS is case sensitive,in the example given below you will undertand that <b>JS does not accept var as VAR/Var</b>. Indeed it will accept only the <b>CamelCase/var with underscore and a hyphen</b>. But hyphen is not usually preffered as it is a reserved
  function for <b>subtraction</b>.
</p>
<p id="demo"></p>
&#13;
&#13;
&#13;

现在我遇到的问题是当我键入此代码并执行它时,它只显示我的lastName而不是我的first_name.So哪些更改我应该引入此代码以便JS可以同时显示first_name&amp;姓。如果JS区分大小写,那么如何识别正确的变量?

1 个答案:

答案 0 :(得分:2)

通过将内容替换为first_name,当您将demo插入lastName时,会覆盖var first_name = "Shaunak"; var lastName = "Gujjewar"; var name = first_name + ' ' + lastName; document.getElementById("demo").innerHTML = name;

你可以先连接它们:

column-fill