0%

Introduction to JavaScript I

  • Run
  • Declare
  • Variables vs constants
  • Primitives*6
    string, number, boolean, undefined, null, symbol
  • References*3
    object, array, function
  • Basics of array, string, function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// run: in browser or node
console.log("hello world!");
// node index.js // run in node

// variable
// use let to declare a variable
let name //undefined
name = "Chandler";
console.log(name);

// constants, don't need to assign
const interestRate = 0.3;
// interestRate = 1;
console.log(interestRate);

// primitive/value types * 6
// string, number, boolean, undefined, null, symbol. primitive types don't have properties and methods, only object types do.
let firstName = "Monica";
let age = 30; // don't have float numbers or integers, all are number type
let isApproved = true;
let lastName; // undefined
let middleName = null; // type: object

// dynamic typing
// type of variable can be changed.


/* // refrence types * 3
// object, array, function */

//object
let person = {
name: 'Ross', // property
age: 10
};
// dot notation
person.name = "Rachel";
// bracket notation
person["name"] = "Emma";
let selection = "name";
person[selection] = "Pheabe";
console.log(person)

// arrays
let selectColors = ['red','blue']; // type: object
selectColors[2] = 'green';
selectColors[3] = 20;
console.log(selectColors);
console.log(selectColors.length);
console.log(typeof(selectColors));

// functions
// function is a set of statements that either performs a task or calculate and returns a value.
function greet(firstName,lastName){ // name: parameter
console.log('Hello ' + firstName + ' ' + lastName);

} // do not need to terminate with ;
greet('Joey'); // argument
greet('Chandler','Bing');

// calculating a value
function square(number){
return number*number;
}
let number = square(2);
console.log(number);


// string primitive
const message = 'hi';
console.log(typeof message)
// string object
const another = new String('hello');
console.log(typeof another)

Thanks for @Mosh‘s great video tutorials.

-------------End of blogThanks for your reading-------------