Hex to Hex String [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 days ago.
The community is reviewing whether to reopen this question as of 7 days ago.
Improve this question
I am converting hex to hex strings then came across 2 ways to do it using the toString() method:
toString('hex')
toString(16)
I see a lot of resources online also use toString('hex') but when I tried to use it, it gives out an error message: RangeError: toString() radix argument must be between 2 and 36.
The toString(16) works perfect.
But just for curiousity, what is the story behind this? Is the toString('hex') deprecated of some sort? Or is there any specific use-case when that is used instead of toString(16)
Example:
let num = 0x7
console.log('Convert using toSting(hex): ' + num.toString('hex')) // throws an error
console.log('Convert using toSting(16): ' + num.toString(16))

Related

How to craete a interface in typescript for an array such that every odd memmber is a number and every even member is a string. I need some interface [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
How to craete a interface in typescript for an array such that every odd memmber is a number and every even member is a string.
I know tuple like [number,string] but it limits the number of element in array .
Also using union(|) will result into anyone can be number or string (number|string)[].
I need something that work for [1,'aa',2,'bb'].
I need a interface that can work with [1,'ajay',2,'abcd',3,'defg']
with any number of items in array.

javascript - new Date('1611065280155').getDate() returns NaN [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying on the Google console.
new Date('1611065280155').getDate() which returns NaN and I was expecting 'yyyy/mm/dd' similar format.
How do I get the date from a milliseconds?
I was referring to https://www.codegrepper.com/code-examples/delphi/get+the+date+in+different+format+javascript but since there are many functions and got confused
You could use Date with a number as value for handing over epoch time.
console.log(new Date(1611065280155));

How to escpe the '/' character in a variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm currently creating directories with a variable called currentDate.
I am trying to create the following directory:
business/bookings/15/06/2020 //3 levels down. the date is a level.
with business/bookings/currentDate
However, JavaScript and Firebase will interpret the '/' as another directory.
How could I solve this problem given that I'll get a variable that's always formatted this way?
A very simple substitution would be with escape/unescape, but nowadays I'd probably use encodeURIComponent/decodeURIComponent:
encodeURIComponent("business/bookings/currentDate")
"business%2Fbookings%2FcurrentDate"
decodeURIComponent("business%2Fbookings%2FcurrentDate")
"business/bookings/currentDate"
Short version: you can't.
The / character is not admitted in file (and directories) name. What you can do is to substitute the slash character with something else.
Hope this helps.

why ` is different than ' in JavaScript? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I started learning JavaScript, and I have faced this problem with strings.
the problem is
and the result is
Why are the results different?
`` - this is 'backtick' - when you use those characters, this is template string. This syntax allows you, to use for example, multiline strings or nested js variables ${}.
'' or "" - this is standard js syntax for strings, you cannot use here ${}

convert string num to number javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I was ask a question in an interview to convert a string number to a number.
eg : My string is "TEN" . and I have to convert it to number 10.
Please help.
Thanks
if (string === "TEN") value = 10;
I think you misunderstood the interviewer's question. He meant getting the number that is currently in a string, not getting the number that is currently spelled out in a string.
But this has already been answered: https://stackoverflow.com/a/4090577/2725684

Categories