<!DOCTYPE HTML> <html> <head> <title>Title of the document</title> </head> <body> <h1>My first application</h1> <span id="lblResult"></span> <script> var a = "10"; var b = (a + 2) / 2; document.getElementById("lblResult").innerHTML = b; </script> </body> </html>
Marry Christ Apr 03 2020
1. Debug with chrome (recommend)
You can follow by bellow link with step by step form Google chrome
OR see video here
See video and work follow
3. Other browsers
You can go to google search and type "how to debug js in Browser name" will have the answer for you.
Back to your question "why the result is 51 but not for 6"
Answer: a variable is a string and we have a rule string + number = string so "10"+ 2 = "102"
=> "102" / 2 = 51
Maybe you will question why string / number = number?
you should remember operator / and * only use for number and them auto convert string to number, so if the string is not a number you will get a value of NaN.
Ex: "a" + 2 = "a2" but "a" / 2 = NaN.