下载node。
1. 申明变量
variables.js
let message = "Hello!";
message = "World";
console.log(message);
node variables.js
2. 申明不会变的变量
const COLOR_GREEN = "green";
console.log(COLOR_GREEN)
3. 数据类型
Data Types = [number, BigInt, string, boolean, null, undefined, Symbol, Object]
// string
let favoriteFruit = 'strawberries';
let favoriteIceCream = "chocolate";
let favoriteProgrammingLanguage = `Javascript`;
// number
let numberOfDonuts = 12;
let pi = 3.14;
// BigInt
let veryLargeNumber = 5435434363466n;
// boolean
let lovesCoding = true;
// undefined
let favoriteColor;
console.log(favoriteColor);
// null
favoriteFruit = null;
// Symbol
const uniqueKey = Symbol();
// Object
let course = {
name: 'JavaScript',
hours: 3
}
4. 动态类型
let firstName = 'Steven';
console.log(typeof firstName);
firstName = 100;
console.log(typeof firstName);
firstName = true;
console.log(typeof firstName);
string
number
boolean
5. Objects
let course = {
name: 'JavaScript',
hours: 3
};
console.log(course.name);
course.name = 'Python';
console.log(course.name);
console.log(course['name']);
course['name'] = 'Java';
console.log(course['name']);
let property = 'hours';
console.log(course[property])
JavaScript
Python
Python
Java
3
6. Arrays
let productColors = ['blue', 'green'];
console.log(productColors[0])
productColors[0] = 42;
console.log(productColors[0])
console.log(productColors.length)
blue
42
2
7. Functions
function sayHi(name){
console.log('Hi! ' + name);
}
sayHi('Steven');
function multiply(num1, num2) {
return num1 * num2;
};
console.log( multiply(2, 2) );
标签:console,log,firstName,variables,JavaScript,course,初级,let,name
From: https://blog.csdn.net/weixin_57266891/article/details/142993920