BillyRayPreachersSon
Programmer
After a comment that was made some time ago about using "correct" methods to do things in JS, I've been thinking about the way we code things, and their alternative methods.
While the following all work 100% (as far as I know), does anyone know of any reason why the alternatives should not be used?
1: Using "var newArr = [];" instead of "var newArr = new Array();"
2: Using "var newInt = '75' - 0" instead of "var newInt = parseInt('75', 10);"
I've been thinking that some alternatives have made it into common use so much that we rarely, if ever, use the original syntax. For example, how often do you see:
var newStr = new String();
instead of
var newStr = '';
to define a new string?
This isn't really a question I'm desperate to find an answer for, but Id be interested on hearing peoples views on the syntax and use of JavaScript, as it's pretty much my primary programming language.
Dan
While the following all work 100% (as far as I know), does anyone know of any reason why the alternatives should not be used?
1: Using "var newArr = [];" instead of "var newArr = new Array();"
2: Using "var newInt = '75' - 0" instead of "var newInt = parseInt('75', 10);"
I've been thinking that some alternatives have made it into common use so much that we rarely, if ever, use the original syntax. For example, how often do you see:
var newStr = new String();
instead of
var newStr = '';
to define a new string?
This isn't really a question I'm desperate to find an answer for, but Id be interested on hearing peoples views on the syntax and use of JavaScript, as it's pretty much my primary programming language.
Dan