0

how can I do following code in typescript like python?

let startDay: Date = new Date();
let startDay: string = `${startDay.toLocaleDateString('en-US')}`

? or I have to declare two different variable for type convention?

1
  • The ${...} is unnecessary here, you could just write startDay.toLocaleDateString('en-US') since that returns a string anyway. Commented Feb 5, 2020 at 23:55

1 Answer 1

2

Yo cannot declare the same variable twice in the same context. Javascript or Typescript will not let you do it. Furthermore, Typescript does not allow type mutation so if you use a Date type first, it cannot be changed.

If you don’t need to use the Date version just omit its declaration:

let startDay: string = new Date().toLocaleDateString('en-US');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.