0
$\begingroup$

A literal is a piece of data which gets its value at compile time.

Means: Becomes set at compile time and afterward the value is fixed incorporated into the machine code as a code consisting out of 0s and 1s.

What are literals in interpreted languages like for example JavaScript?

As far as I know the code within JavaScript functions aren't touched by the interpreter until it becomes executed.

Can one say that literals exists in these languages? regarding my definition of a literal (first paragraph).

$\endgroup$
2
$\begingroup$

A literal is a piece of data which gets its value at compile time.

I don't think that's a good definition of literals. A literal is a source-code token that represents a fixed value of some type. For example, in almost all programming languages, 23 is a literal representing the integer twenty-three. These aren't pieces of data that get their value at compile-time: rather, they are representations of the values themselves. For example if, in Java, you write

static final int magic = 23;

then magic is a constant (a variable whose value cannot be changed) that is set at compile-time to have the value twenty-three, which is the meaning of the literal 23.

This is no different between compiled and interpreted languages.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.