Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

Test your website on
3000+ browsers

Get 100 minutes of automation
test minutes FREE!!

Test NowArrowArrow

KaneAI - GenAI Native
Testing Agent

Plan, author and evolve end to
end tests using natural language

Test NowArrowArrow
DebugJavaScriptMiscellaneous

TypeError: JavaScript

TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function.Therefore, it becomes necessary to make sure variables must have same data types before performing any operation.Type mismatch generates an error while executing the whole program.

Author

Saif Sadiq

December 19, 2025

Can you add a number and an alphabet?

Say, if I ask you to give me the result of the addition of 1 and H will you be able to give me the answer?

The obvious answer is NO.

Same goes in JavaScript too!If you add 1 and H in JavaScript or when you try to perform operations on two operands of unmatched type, JavaScript throws a TypeError.

So, you can say in technical terms that ‘TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function’.

Therefore, it becomes necessary to make sure variables must have same data types before performing any operation.Type mismatch generates an error while executing the whole program.

Types of TypeError

For example, you will get Uncaught TypeError if you are trying to convert a number to uppercase character. As toUpperCase() is a function to convert a string to uppercase characters.It will give an error for following code structure.

Code structure

var num=1;
try{
num.toUpperCase();
}
catch(err) {
    document.getElementById("demo").innerHTML = err.name;
}

Error

...

How to get rid of this Uncaught type error: Cannot set property

There are many methods possible to overcome this error.

1.Using toString() function

You can use toString() function to convert number into string first and then you can convert that string to upper case characters using toUpperCase() function.

var num = 1;
try {

    num.toString().toUpperCase();   // Convert number into string first 
}
catch(err) {
    document.getElementById("demo").innerHTML = err.name;
}

Output

"1"

2. Using constructor new String() of predefined class

var num = 1;
num=new String(num);
try {

    num.toUpperCase();   // You cannot convert a number to upper case
}
catch(err) {
    document.getElementById("demo").innerHTML = err.name;
}

Output

Here are few more TypeError that can be thrown by JavaScript in different browsers.

Author

Saif Sadiq is a community contributor with 7+ years of experience working across product, growth, and developer-focused platforms. Currently Director of Product & Growth at Apptile, he leads product strategy and cross-functional execution for no-code mobile app tooling. Saif previously worked at TestMu AI, contributing to product and growth initiatives for a cloud-based cross-browser testing platform, and has been recognized as a most-viewed blogger and writer.

Did you find this page helpful?

More Related Hubs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests