<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
console.log(a)
console.log(c)
var a = 1
var c = function () {}
function a() {}
console.log(a)
console.log(c)
//打印
// f a() {}
// undefined
// 1
// f() {}
</script>
<script>
let obj = { a: 1, b: 2 }
//
// 你的代码
//
Object.defineProperty(obj, 'a', {
writable: false
})
obj.a = 10
console.log(obj.a) // =>应该 输出 1 不应该输出10
</script>
<script>
// 获取网页中的所有元素
let allElements = document.querySelectorAll('*')
// 创建一个对象来存储每个标签的出现次数
let tagCount = {}
// 遍历所有元素,统计每个标签的出现次数
Array.from(allElements).forEach((element) => {
let tagName = element.tagName
if (tagCount[tagName]) {
tagCount[tagName]++
} else {
tagCount[tagName] = 1
}
})
// 将对象转换为数组
let tagArray = []
for (let tagName in tagCount) {
tagArray.push({ tagName: tagName, count: tagCount[tagName] })
}
// 对数组进行排序,找出使用次数最多的三个标签
tagArray.sort((a, b) => b.count - a.count)
// 输出使用次数最多的三个标签
let topThreeTags = tagArray.slice(0, 3)
console.log(topThreeTags)
// 在这个代码中,document.querySelectorAll("*")用于获取网页中的所有元素,
// 然后我们使用Array.from(allElements).forEach来遍历这些元素,统计每个标签的出现次数。
</script>
</body>
</html>