Js parseInt type conversion problem

topic description

Why is the output of parseInt ("12 percent, 2) 1?

thought
the binary number 12 does not exist. Shouldn"t the result be NaN?

related codes

console.log(parseInt("12", 2)); // 1
Mar.08,2022

parseInt tries to match and convert until it encounters characters that cannot be converted. So in your example, it matches and converts the character 1, while 2 is ignored

.
Menu