TypeScript + Symbol

Asked 2 years ago, Updated 2 years ago, 55 views

  checkId(userId: string): Promise<User> {
    return userPromise
      .then(children => children.find(children => children.id === +userId));
  }

In the example code above, the statement of child === +userId is + goes in, but I don't know why + goes in. Please give me an answer.

https://github.com/wikibook/ng2-book/blob/master/router/src/app/auth.service.ts

typescript angular

2022-09-21 18:17

1 Answers

It is used when converting to the number type in JavaScript.

var stringValue = "12345";
console.log(typeof stringValue);
//output : string

var stringToNumber = +stringValue;
console.log(typeof stringToNumber);
//output : number

var stringToNumber2 = Number(stringValue);
console.log(typeof stringToNumber2);
//output : number


2022-09-21 18:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.