控制台日志颜色含义

Eli*_*th 2 javascript console frontend console.log

我很好奇控制台日志中显示黑色或蓝色的数字有什么区别?

我目前正在使用此变量输出:

currentImageIndex = currentImage.attr('data-index'),
Run Code Online (Sandbox Code Playgroud)

它确实在控制台中输出了正确的数字。它以黑色显示数字。由于某种原因,即使输出了正确的数字,我的函数也不起作用。但如果我写下以下内容:

currentImageIndex = 5, 
Run Code Online (Sandbox Code Playgroud)

该功能将起作用。我注意到该数字在控制台日志中显示为蓝色。有什么不同?

Cer*_*nce 5

黑色表示字符串,蓝色表示数字:

在此输入图像描述

元素属性始终是字符串;.attr返回一个字符串。您需要将其转换为数字:

currentImageIndex = Number(currentImage.attr('data-index'));
Run Code Online (Sandbox Code Playgroud)