Hacker News new | ask | show | jobs
by lucideer 1994 days ago
I don't know why that space is there, it could be accidental or a deliberate stylistic quirk of the author, but it seems harmless (if not idiomatic).

> How is this valid JS? What does it do?

I'm curious if Python (or a similar whitespace-sensitive syntax) is your first/familiar programming language.

The extra whitespace here does nothing.

The semicolon in JS is an (optional) expression separator, similar to in Bash/Shell. It can occur at the end of a line or at the beginning of a line, or in between lines. Or in between two expressions on a single line. Any whitespace chars before or after it are irrelevant/ignored.

1 comments

It is not clear how this response is meant to answer the question in the post you replied to; there was no mention of whitespace.

Their question was:

>Why is there a string right after the field "button" of the object "styled"?

which unambiguously refers to the double backtick characters between "styled.button" and the semicolon in this expression:

> export const Button = styled.button``;

That is, in JavaScript, an empty string. There is not whitespace and Python has nothing at all to do with the question. Similarly, an explanation of what a semicolon does in JavaScript does not answer the question.

I also can't answer the question for them as I haven't kept up with newer JavaScript standards, but I thought it important that you realise you misunderstood something here.

Possibly a HN formatting issue (or the commenter typed wrong first time and later edited) but the backticks weren't showing up previously.

Sorry @Traubenfuchs for the misguided explanation.

As another commenter posted, this is a template tag. Technically equivalent to doing something like styled.button('') but the template tag syntax would be used for consistency with other calls in the code (where parameterised template strings would be passed to the button/element/component method)