JavaScript data types, variables, variable scope, literals, hoisting

JavaScript has five primitive data types,

  • Undefined 
  • null – a special keyword denoting a null value.
  • Boolean – a logical entity that consists of either a true or false value.
  • Number – a set of numerical digits that represent a number.
  • String – a set of zero or more characters.

Variables

You can use variables as symbolic names for values in application. The names of variables, is called identifiers. Variables can be declared with keyword “var”.

Variable scope

When you declare variables outside of function , its called global variable. When you declare within a function, its called local variable. JavaScript does not have block statement scope.

Hoisting

You can refer to variable declared later without getting exception. This concept is called “Hoisting”, variables in JavaScript are in a sense “hoisted” or lifted to the top of the function.

Constants

You can create read-only, named constant with “const” keyword.  A constant cannot change value through assignment.

Literals

These are fixed values, not variables, that you literally provide in you script.

Array Literals

var coffees = ["French Roast", "Colombian", "Kona"];

Boolean Literals

The boolean type has two literal values “true”, “false”.

Object Literals

An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces.

String literals

A string literal is zero or more characters enclosed in double or single quotation marks.

References

https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: