0

An identifier is simply a name and a namespace is also a name but to a literal.

I just got this question in a discussion forum, but I was not happy with answer (above) given.

2
  • 2
    What was the answer? Commented Nov 18, 2014 at 12:31
  • In JavaScript, when we talk about a namespace, it is actually a variable member in an object, itself representing an object. The global object being window. A literal is a number, true, false, null or a string, not an identifier. (at times, undefined is also viewed as a literal, but it should be a non-defined identifier.) Commented Nov 18, 2014 at 12:54

1 Answer 1

1

An identifier is simply a name. In JavaScript, identifiers are used to name variables and functions and to provide labels for certain loops in JavaScript code. The rules for legal identifier names are the same in JavaScript as they are in Java and many other languages. The first character must be a letter, an underscore (_), or a dollar sign ($).Subsequent characters may be any letter or digit or an underscore or dollar sign. (Numbers are not allowed as the first character so that JavaScript can easily distinguish identifiers from numbers.) Read more

Namespacing in Javascript is achieved by defining properties on the Global Object, in browsers that is the window object. Every var declaration performed in the global context will create the variable under the window object, making it available globally.Read more

var one = 1;
window.one === one; // true
function fn() {
 1 === one; // true 
 }
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.