Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:06:47+00:00 2026-06-12T02:06:47+00:00

I am puzzled by this snippet : var n1 = 5-4; var n2 =

  • 0

I am puzzled by this snippet:

var n1 = 5-"4";
var n2 = 5+"4";

alert(n1);
alert(n2);

​I understand that n1 is 1. That is because a minus operator would convert the string “4” into number and subtract it from 5.
But why do we get 54 in case of + operator?

Can someone explain this difference between + and = operators to me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:06:49+00:00Added an answer on June 12, 2026 at 2:06 am

    By type conversion any + expression, that contains a strings, will result in a string. Thus all operands (in your case 5) will be converted to a string, before executing the concatenation.

    - on the other hand is just an arithmetic operand, thus "4" is converted to an integer and the calculation is performed as you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this snippet of SQL in a view and I am rather puzzled
I'm puzzled by this notation that did spread a lot after the first templating
I am very puzzled on this matter that I can only write image to
I am so puzzled. I am using this open-source snippet. I have a table
Consider this C# snippet: static string input = null; static string output = null;
I am very puzzled about this code: var closures = []; function create() {
I use asp.net, c# and EF4. I'm puzzled by this LINQ query: var queryContents
I am puzzled why this return false doesn't cancel the post-back. function validate() {
I am really puzzled by this. I believe I am managing memory the correct
okay...im really puzzled with this. I want to create a regular asp.net webforms website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.