Result of addition returns NaN but when I check typeof it returns number

Hello I will paste my code here, the problem it that it doesnt add numbers,i did some checks but the result return Nan and I dont understand why…

var clickCounter = 0;
var first = 1;
var second = 1;
var rezultat = 1;
function noua() {
first = 9;

function opt() {

if(clickCounter != 0) {
  second = 8;


function adunare(first, second) {
rezultat = first + second;

function afiseaza() {
console.log(typeof first);
console.log(typeof second);
console.log(typeof rezultat);


function before() {
console.log("first= "+first);
console.log("second= "+second);
console.log("rezultat= "+rezultat);

It seems clear that you have other code that you haven’t shown to us yet, as that code above doesn’t do much at all by itself.

I will assume that the most common reason is the cause of your problem, and that common reason is where the parameters going to the adunare function are not numbers, but are instead either strings or undefined.


As Paul says, something you’re passing to the adunare function isn’t a number.

You’ve tripped yourself up by calling your local parameters and your global variables the same name.


Thanks it was from the parameters…i solved it

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.