here is the difference ......... Please make your attention in the '<%= txtname.ClientID %>' tag.....started and ended with a Apostrophe (’)
.................
alert('<%= txtname.ClientID %>');
var V = <%= txtname.ClientID %>
alert(V);
and if you want to a control to a js file then do somthing like this in ASPX page
var V = document.getElementById('<%=txtName.ClientID%>');
Or
var V1 = $('#' + '<%=txtName.ClientID%>');
myfunction(V1);
and in .js file read the value
function myfunction(V) {
alert(V.value);
}