mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-22 23:01:41 +03:00
Tidy up section on variables, arrays and objects
This commit is contained in:
parent
7c4bd7120c
commit
c2d5429472
@ -108,13 +108,16 @@ undefined // used to indicate a value that hasn't been set yet
|
|||||||
|
|
||||||
// Variables are declared with the var keyword. Javascript is dynamically typed,
|
// Variables are declared with the var keyword. Javascript is dynamically typed,
|
||||||
// so you don't need to specify type. Assignment uses a single = character.
|
// so you don't need to specify type. Assignment uses a single = character.
|
||||||
var some_var = 5
|
var someVar = 5
|
||||||
|
|
||||||
// if you leave the var keyword off, you won't get an error...
|
// if you leave the var keyword off, you won't get an error...
|
||||||
some_other_var = 10
|
someOtherVar = 10
|
||||||
|
|
||||||
// but your variable will always end up with the global scope, even if it wasn't
|
// ...but your variable will be created in the global scope, not in the scope
|
||||||
// defined there, so don't do it.
|
// you defined it in.
|
||||||
|
|
||||||
|
// Variables declared without being assigned to are set to undefined.
|
||||||
|
var someThirdVar // = undefined
|
||||||
|
|
||||||
// Arrays are ordered lists of values, of any type.
|
// Arrays are ordered lists of values, of any type.
|
||||||
["Hello", 45, true]
|
["Hello", 45, true]
|
||||||
@ -133,7 +136,7 @@ myObj["my other key"] // = 4
|
|||||||
// ... or using the dot syntax, provided the key is a valid identifier.
|
// ... or using the dot syntax, provided the key is a valid identifier.
|
||||||
myObj.myKey // = "myValue"
|
myObj.myKey // = "myValue"
|
||||||
|
|
||||||
// Objects are mutable, values can be changed and new keys added.
|
// Objects are mutable; values can be changed and new keys added.
|
||||||
myObj.myThirdKey = true
|
myObj.myThirdKey = true
|
||||||
|
|
||||||
/***********
|
/***********
|
||||||
|
Loading…
Reference in New Issue
Block a user