Arrays Hold multiple values in comma-separated list
JAVASCRIPT : BASICS II
// Arrays can hold a mix of data types
let numArray = [13, 36, 45, 57, 14];
let mixedArray = ["a", "b", 1, 2, 3];
Objects Store multiple key : value pairs, or properties
const book = {
.length Property tells us the length of an array
title: "The Hobbit",
let fruits = ["apple", "banana", "orange"]; author: "J.R.R. Tolkien",
// Assign array length to a variable year: 1937
const numFruits = [Link]; };
[Link](numFruits); // Output: 3
Dot Notation Used to access, add, & update object properties
// Access a property
Array Methods Used for editing array elements
[Link]([Link]);
// Adds element to end of array // Output: The Hobbit
[Link]("pear");
// Assign a new property
// Adds element to beginning of array [Link] = "1st Edition";
fr
[Link]("strawberry");
[Link](book);
// Removes and returns the first element /* Output: {
fr
[Link](); title: "The Hobbit",
year: 1937,
// Removes and returns the last element author: 'J.R.R. Tolkien',
fr
[Link](); edition: '1st Edition'} */
// Returns the index of the value // Update a property
fr
[Link]("apple"); [Link] = "2nd Edition";
// Returns true or false if value in array [Link](book);
fr
[Link]("dragonfruit"); /* Output: {
title: "The Hobbit",
year: 1937,
author: 'J.R.R. Tolkien',
Function Keyword used to define a function edition: '2nd Edition'} */
// JS function names are in camelCase
function myFunction() {
Object Methods Function defined as properties
[Link]("Hello, World!");
} const dog = {
myFunction(); name: "Benny",
sound: "woof",
// Method returns a string
Return Keyword sends value back from a function makeSound() {
return [Link] + " says " + [Link] + "!")
function myFunction() { }
return "Hello, World!"; };
}
// Will not appear on console [Link]([Link]());
myFunction(); // Output: Benny says woof!
Made with by