Javascript missing semicolon/'a' is undefined; please fix or add



Hey all,

So I saw there was a thread similar to this but it was dealing more with importing other classes into a file. My question is a simple syntax one:

// in a file named “test.js"
if (typeof a != ‘undefined’) document.write(‘a = "’ + a + '”
if (typeof b != ‘undefined’) document.write(‘b = "’ + b + ‘"
if (typeof c != ‘undefined’) document.write(‘c = "’ + c + ‘"

function test()
a = 123
var b = 456
if (a == 123) var c = 789

So this is all completely valid JS code and I’ve tried it and it works. However my gutter is littered with warnings about how these lines are all missing semicolons. Not only that, but it tells me that a is not defined and c is defined but never used. I don’t want to turn off warnings like this completely in case I do actually make a mistake later on but they are really annoying right now. Any suggestions?



While your code works now, the purpose of the eslint implementation at Cloud9 is to help you code using current coding standards. In your case, you never declare “var a”, meaning that your code, while it works, will fall into this scenario: (you can read more on the horrors of global variables in the link provided in the answer).

For disabling eslint on a file-to-file basis, you can use the proposed solution here:

I hope this helps!



If you really want to, you can also disable checking for undeclared variables and missing semicolons from project settings

And can fine tune eslint options with .eslintrc

VarName is not defined, please fix or add /*global VarName*/ Cloud9

@harutyun thanks for the help! @dana you are absolutely right and thank you for pointing me in the right direction. It turns out the book I was using to learn JS in the first place is actually pretty outdated! I want to learn best practices so I’m going to try and hold my code to more current standards. Thanks again to both!


try using this book, Eloquent Javascript
It is free and really awesome, and somewhat funny to read.