0% found this document useful (0 votes)
10 views

Java Script 1

Uploaded by

jtomm2covj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java Script 1

Uploaded by

jtomm2covj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

const suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs'];

const values = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King'];

const deck = [];

for (const suit of suits) {


for (const value of values) {
const card = `${value} of ${suit}`;
deck.push(card);
}
}

// Create an array with 40 undefined elements:


const points = new Array(40);

Primitive vs Reference
Let,var, const name = “Phani”, 70, true etc
Reference array, object, dict,
var person = {
name: 'Max',
age: 28,
}
var hobbies = ['Sports', 'Cooking']
difference = memory management
stack vs Heap
The stack is essentially an easy-to-access memory that simply manages its items
as a - well - stack. Only items for which the size is known in advance can go
onto the stack. This is the case for numbers, strings, booleans

For each heap item, the exact address is stored in a pointer which points at the
item in the heap. This pointer in turn is stored on the stack. That will become
important in a second.

Let,var,const on a object lets you to change the properties inside the object edit
delete add them, but you cant assign it a new object

When you say var array1 = [….] , then array2 = array1 you copy the pointer, to
copy the value of an reference type
You basically need to construct a new object or array and immediately fill it
with the properties or elements of the old object or array.
var hobbies = ['Sports', 'Cooking']
var copiedHobbies = hobbies.slice()

You might also like