Как узнать тип переменной в JS

Узнать тип переменной можно с помощью оператора typeof. Смотрите пример:

javascriptlet str = '123456';
let num = 123456;
let arr = [1, 2, 3, 4, 5, 6];

console.log('str', typeof(str));
console.log('num', typeof(num));
console.log('arr', typeof(arr));

Результат выполнения кода:

javascript'str' string
'num' number
'arr' object

Смотрите также

  • оператор typeof,
    который определяет тип данных