console.log基本使用
时间: 2024-02-21 18:36:08 浏览: 125
console.log()是JavaScript中最基本和常用的用法之一,它可以在浏览器的控制台中打印信息。基本使用方法如下:
1. 使用console.log()打印一个变量的值:
```javascript
let name = "HHHHH";
console.log(name); // HHHHH
```
2. 使用console.log()打印带有字符串的信息:
```javascript
let name = "HHHHH";
console.log(`my name is: ${name}`); // my name is: HHHHH
```
3. 使用console.log()打印多个变量或值:
```javascript
let name = "HHHHH";
let age = 18;
console.log(name, age); // HHHHH 18
```
4. 使用console.log()打印带有描述信息的变量或值:
```javascript
let name = "HHHHH";
let age = 18;
console.log("message:", name, age); // message: HHHHH 18
```
通过console.log()方法,可以方便地在控制台中查看变量的值、输出测试信息或进行调试。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [console.log() 的小技巧](https://blog.csdn.net/Hannaaa/article/details/121149740)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [console.log(console.log) = ?](https://blog.csdn.net/lefex/article/details/105721791)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文