JavaScript values, variables

If you try to declare a variable that already exists, JavaScript will treat it as a simple assignment statement and assign any new value in the declaration statement to the variable. If the duplicate declaration has no assignment, then nothing happens. If you try to assign a value to a non-existent variable, JavaScript will create the variable for you.

<script type="text/javascript">
//Commented lines starting with the double


//First we will declare a few variables
//and assign values to them


myTxt = "Do IT";
mynum =13;
//Note that myTxt is a string and mynum is numeric.

//Next we will display these to the user.

document.write(myTxt);

//To concatenate strings in JavaScript, use the '+' operator 
document.write("My favourite number is "+ mynum);
</script>