0

Javascript

let num = 10;

in this case, is num a variable or an identifier?! can someone explain with an example the difference (if any) between a variable & an identifier?

shashah
  • 11
  • 4
  • An *identifier* is some string of characters that can be used as a variable name. A *variable* is a symbol declared in some context, and its name must be a valid identifier. – Pointy Jul 07 '21 at 18:08
  • The concept *identifier* appears in the language syntax in more situations than variables. For example, a function name must be an identifier, as must be function parameter names. – Pointy Jul 07 '21 at 18:10
  • Think of an Identifer as a "label" for something like a bucket, which holds a value. Or more importantly a reference to a value in Javascript. let bucketOfDirt = "sand"; The identifier for my variable is `bucketOfDirt`, in other words its a name given to a `variable, function, property`. There are some rules for naming e.g. you cannot use keywords in JavaScript as variable names – Harry Jul 07 '21 at 18:16

0 Answers0