JS Introduction and JS Variables

0 41

JS Introduction Variables Js Versions Tags JS Variables and Naming Rules

in this tutorial we will briefly talk on JS Introduction Variables Js Versions Tags JS Variables and Naming Rules

JavaScript

Consider an online shopping website where a customer can add or remove products from cart further can add on an interested list and at the end a customer can buy online products by providing credit card information.to handle all these task web developers need to handle all task dynamically like credit card number email and phone number entered by the customer must be in proper and valid format and also chosen products and their quantity to calculate the total cost.

To handle all these task developers need a scripting language. Scripting language provides some functionality to handle all these tasks when the user interacts with a webpage. JavaScript is an object-oriented language to handle dynamic behavior on a web page. Its syntax similar like C and java languages major difference in JavaScript is it don’t have classes like C and java languages. Class functionality handled in JavaScript with object prototypes.

Scripting

Scripting refers to a series of commands that are interpreted and executed sequentially. This action event generated by a user interacting with a Web page, for example, an event occurs when a button is clicked or user selected products from the list.
Two type scripting language there and they are…

Client-side Scripting

Client-side scripting languages executed on user’s machine by the browsers.

Server-side Scripting

Server-side scripting language executed on a web server to generate dynamic HTML pages.

Versions of JavaScript

The first version of JavaScript was developed by Brendan Eich at Netscape in 1995 and was named JavaScript 1.0.
Over the period JavaScript 1.0 gradually involved with the newer version by included better features and functionalities comparing its old versions.
JavaScript versions are

Version Description
1.1 Is supported from 3.0 version of the Netscape Navigator and Internet Explorer
1.2 Is supported by the Internet Explorer from version 4.0
1.3 Is supported by the Internet Explorer from version 5.0 Netscape Navigator from version 4.0 and Opera from version 5.0
1.4 Is supported by servers of Netscape and Opera 6
1.5 Is supported by the Internet Explorer from version 6.0 Netscape Navigator from version 6.0 and Mozilla Firefox from version 1.0
1.6 Is supported in the latest versions of the Internet Explorer and Netscape Navigator browsers. It is also supported by Mozilla Firefox from version 1.5
1.7 Is supported in the latest versions of the Internet Explorer and Netscape Navigator browsers. It is also supported by Mozilla Firefox from version 2.0

Note – The latest version JavaScript 2.0 still into the development phase.

<Script> Tag

To define a JavaScript code in HTML page <Script> </Script> Tag used. <Script> Tag can be used either in the head element or in body element of the html document.

JS Variables

Variables in JavaScript

Variable is a container to hold a value and store in a memory at a unique location in RAM for the example student name age roll number salary of an employ etc.
The variable name always used to access and read the value stored in it. Therefore variable act as a container for saving and retrieving values during the execution of the JavaScript.

Declaring Variables

Declaring a Variable refer to creating a variable by specifying the variable name.To store a student name you can create the stuName variable. Here stuName is an identifier
In JavaScript, var keyword used to create a variable by allocating memory.A keyword refers to a reserved word which is reserved for language. We can assign value to the value to a variable at the start of creation or later. Once the value is initialized to variable its value can be change later as required.

Syntax:
var <variableName>

var is the keyword to allocate memory for variable.
variableName Is a valid variable name.

Variable Naming Rules

JavaScript is a case-sensitive programming language for example if you create x and X variable both are treated as two different variables.Always give meaning full name later it will be easy to debug code and fix errors.

Like other OPPS programming languages, JavaScript also defined some naming conventions for variable Names.

  • Should be consist on digits, underscore, and alphabets.
  • Must begin with a letter or the underscore character.
  • Cannot begin with a number and cannot contain any punctuation marks.
  • Cannot contain any kind of special characters such as +, *, %, and so on.
  • Cannot contain spaces.
  • Cannot be a JavaScript keyword.

Comments

comments

Leave A Reply

Your email address will not be published.