- use strict
- var
var - variables in JavaScript
examples/js/var.js
"use strict"; var user_name = 'Foo'; console.log(user_name); // "Foo" var age = 42; console.log(age); // 42 age = 23; console.log(age); // 23 user_name = 1; console.log(user_name); // 1 var email; console.log(email); // undefined email = 'foo@bar.com'; console.log(email); // foo@bar.com
- "use strict"; (later explained)
- Declare variables using 'var'
- Variable names start with letters, underscore (_), or the dollar sign.
- Variable names can contain letters, underscore (_), the dollar sign, and digits.
- camelCase is the recommended style in JavaScript, though I think long_names separated with underscores are nicer.