If I copy and paste this into my web page:
<script>
$(function(){
$("#startDate").datepicker();
});
</script>
I get this error in the browser:
Uncaught SyntaxError: Unexpected token ILLEGAL
However, using that exact same code, if I simply delete the final semi-colon and add it again, the code gets formatted within VS 2012 and then it works. Why? I didn't think spacing mattered with JavaScript?
And if I paste that same code and add the spacing myself, it still doesn't work. I have to type it all by hand, or delete and add the semi-colon again. Could this be a bug? Am I missing something elementary?
This is the entire code within the page:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery-ui-1.8.20.min.js"></script>
<script>
$(function(){
$("#startDate").datepicker();
});
</script>
</head>
<body>
<div>
<h2>Home View</h2>
<input type="text" id="startDate">
</div>
</body>
</html>
And just to be complete, this is the code that works:
<script>
$(function () {
$("#startDate").datepicker();
});
</script>
I don't see the difference, other than the spacing. And like I said, I can have that exact code, with the spacing, and it fails unless I delete and add the semi-colon.