Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12231

If statement isn't showing console.log when condition passed and continue work as unexpected

$
0
0

So there's a simple code with vanilla JavaScript.

const button = document.getElementById('btn');const input = document.getElementById('amount');let list = [];button.addEventListener('click', () => {    let num = +input.value;    if (typeof num === 'number') {        list.push(num);        console.log(list);    }    else {         console.log('Error. Try again and type in a number');    }})

Why the console.log statement isn't showing up in the console but instead it pushes NaN value to the list?

I tried to use else if instead of just else and passed the following condition: typeof num !== 'number'


Viewing all articles
Browse latest Browse all 12231

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>