While using JavaScript, we need to know some other important things, may be
these are not explained in all other segments of our JavaScript Tutorial.
Like below....
Case Sensitivity of JavaScript
In JavaScript naming convention of JavaScript functions variables and objects matter
with its case. Let's suppose we use a variable as "username" and we try to call
it as "UserName" its totally invalid and will be the reason of generating
an JavaScript
exceptions. Hence JavaScript is case sensitive language. So we must need
to watch our capitalization closely while using the JavaScript variables names, function names,
and object names.
White Spaces in JavaScript
JavaScript ignores the extra white spaces from the web browser. But we can add white
spaces to our JavaScript code and this convention makes our code more reliable like the
below two blocks are equal and the last one is preferred because of white spaces
makes its quite easy to understand.
Examples of JavaScript White Spaces
Block One :
<script type="text/javascript">var date=new Date();document.write(date);</script>
Block Two :
<script type = "text/javascript">
var date = new Date();
document.write( date );
</script>
JavaScript Comments
Its good to use always comments in your JavaScript to explain for others and
this convention is also helpful even for us in future. Because forgetting is a human
nature and if we forgot some thing and while we look at the comments we can
understand what its happening.
We can add a JavaScript comments in our code with the start of // and this will make our
single line as comment like below code.
Syntax for Single Line JavaScript Comment
<script type = "text/javascript"> //This is a single line comment in JavaScript, we can write any tip help here.
var date = new Date();
document.write( date );
</script>
Or we can use /* for start and
*/ for end of multiple lines JavaScript comments like the blow code.
Example of Multiple Lines Comment in JavaScript
<script type = "text/javascript"> /* This is a multiple lines comment,
we can write any tip help here. */
var date = new Date();
document.write( date );
</script>
Breaking JavaScript Code in multiple lines
We
can't break our JavaScript code in multiple lines but we can break only in case of
JavaScript string
like below code.
Example of breaking JavaScript code in muliple lines
<script type = "text/javascript">
document.write( "JavaScript Tutorial at /
Global Guide Line Technology" );
</script>
Breaking JavaScript Alert in multiple lines
We
can also break our JavaScript alerts into multiple lines like the below code example