Skip to content

JSON: why are forward slashes escaped?

The reason for this “escapes” me. JSON escapes the forward slash, so a hash {a: “a/b/c”} is serialized as {“a”:”a/b/c”} instead of {“a”:”a/b/c”}. Why? Answer JSON doesn’t require you to do that, it allows you to do that. It also all…

How can I invert a regular expression in JavaScript?

I have a string A and want to test if another string B is not part of it. This is a very simple regex whose result can be inverted afterwards. I could do: and invert it afterwards, like this: The problem I have is, that I need to do it within the regular expression and not with their result. Something

Reading cookie expiration date

Is it possible to read cookie expiration date using JavaScript? If yes, how? If not, is there a source I can look at? Answer It is not possible to get the expiration date of a cookie through Javascript; only key-value pairs are exposed through document.cookie.

How do I get the current date in JavaScript?

Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. How do I get the current date in JavaScript? Answer Use new Date() to generate a new Date object containing the cu…

Javascript Date.UTC() function is off by a month?

I was playing around with Javascript creating a simple countdown clock when I came across this strange behavior: The days left is off by 30 days. What is wrong with this code? Edit: I changed the variable names to make it more clear. Answer The month is zero-based for JavaScript. Days and years are one-based.…