diff --git a/arrays/README.md b/arrays/README.md index 0690816e..913d9d19 100644 --- a/arrays/README.md +++ b/arrays/README.md @@ -9,4 +9,12 @@ Here is a simple array: ```javascript // 1, 1, 2, 3, 5, and 8 are the elements in this array var numbers = [1, 1, 2, 3, 5, 8]; + +numbers.length //returns 6 + +//add new element to the numbers +numbers.push(9) //returns [1, 1, 2, 3, 5, 8, 9] + +//remove last element +numbers.pop() // returns [1, 1, 2, 3, 5, 8] ``` \ No newline at end of file diff --git a/objects/immutable.md b/objects/immutable.md new file mode 100644 index 00000000..c0d60032 --- /dev/null +++ b/objects/immutable.md @@ -0,0 +1,15 @@ +# Immutable +Immutable object values cannot be changed once it's declared. +```js +const obj = { + prop: 42 +}; + +Object.freeze(obj); // this will freeze the values + +obj.prop = 33; +// Throws an error in strict mode + +console.log(obj.prop); +// expected output: 42 +``` \ No newline at end of file