Course Banner


Typescript Identifier

Identifiers in TypeScript

We use variables, functions etc in TypeScript and also we give them certain name. But we have to take care of the naming convention also. There are certain rules/convention of naming  variables and functions and these rules are called identifiers.
There are following identifiers.

  • Identifiers can contain both, characters and digits. However, the identifier cannot begin with a digit.

  • Identifiers cannot contain special symbols except for underscore (_) or a dollar sign ($).

  • Keywords cannot be used as identifiers.

  • Identifiers should not be duplicate

  • Identifiers are case-sensitive.

  • Spaces are now allowed in Identifiers..

The following tables lists a few examples of valid and invalid identifiers −

Valid identifiers

Invalid identifiers

firstName

Var

first_name

first name

num1

first-name

$result

1number

TypeScript ─ Keywords

Keywords have a special meaning in the context of a language. The following table lists some keywords in TypeScript.

break

as

any

switch

case

if

throw

else

var

number

string

get

module

type

instanceof

typeof

public

private

enum

export

finally

for

while

void

null

super

this

new

in

return

true

false

any

extends

static

let

package

implements

interface

function

new

try

yield

const

continue

do

catch



Comments in TypeScript

To make our code more readable and more memorable, we take help of comments. You may be very good at coding but its most likely that after few months you may forget your own code wondering why had you used that code.  But, if you have commented properly, it becomes easy to understand.

TypeScript supports the following types of comments −

  • Single-line comments ( // ) − Any text between a // and the end of a line is treated as a comment

  • Multi-line comments (/* */) − These comments may span multiple lines.

Example

//this is single line comment

/* This is a  
  Multi-line comment
*/



Ad Image