I would like to know if Visual Studio 2017 has a tool to verify the java script syntax when compiling a project.
Currently if I have an error a js file, I only realize how much the eject and the browser reports the error.
Thanks for the help.
I would like to know if Visual Studio 2017 has a tool to verify the java script syntax when compiling a project.
Currently if I have an error a js file, I only realize how much the eject and the browser reports the error.
Thanks for the help.
In visual studio 2017 this is already included, if it is not enabled you must do it in the following option:
Tools-> Options-> Text Editor-> JavaScript / TypeScript-> "Enable the new JavaScript Language Service"
with this I should already be checking the javascript syntax the problem is that javascript itself is very permissive, I'll give you as an example the following code:
for(i=0;i<10;i++){
var a = i;
}
console.log(a);
the above code will compile and run without problems and is that in javascript when you declare a variable you send them all up to the section of code where they are running but this can cause confusion when debugging a code javascript so I recommend using the strict javascript mode, example:
"use strict";
for(i=0;i<10;i++){ // error
var a = i;
}
console.log(a); // error
for this case will give error in the use of the variable i
because it is not previously defined and with the case of console.log
something similar will happen since the variable a
is defined in a section of code to which does not have access, using the strict mode the javascript validator detects these problems.
Now, javascript has another kind of problems and it is by its nature, javascript is an interpreted language, not compiled or precompiled, what does this mean? For example, we will put the following code:
var Persona = { nombre: "Juan"};
console.log(Persona.apellido);
The above code does not detect an error and it is because it does not know that the surname variable does not exist until it executes it and that is why most of the languages are compiled or pre-compiled to detect this type of errors, with respect I do not have this knowledge if there is a tool to detect these errors or not. I hope this information serves you, Regards.