Javascript Basics

JavaScript is the world’s most popular programming language. Some of the advantages of javascript are given below:

  • Client side execution
  • Validation on browser
  • Easy language

Disadvantages:

  • It is comparatively less secure.
  • No hardware access

Ways of adding javascript:

Inline – We can javascript inside the head tag or the body tag between <script>…</script>.

External – We can create a javascript file externally and link it inside the head tag or the body tag between <script>…</script>.

To link a java file to html file:-

<script src=”abc.js” type=”text/script”> </script>

Some of the functions of javascript is given below:-

  • Write function

*document.write()

  • It displays the content into page.
  • If we use this function in the end of the HTML document it will delete all existing HTML.
  • It is used only for testing purpose.

Ex:- document.write(variable); , document.write(4+2);

  • Alert function

*window.alert()

  • It displays the data in the alert box.
  • It should be used when you want the user to stop and see the alert.

Ex:- window.alert(“hello world”); , window.alert(“4+2);

  • Identifiers

It is a name having few letters, numbers and special characters.

It is used to identify var, function, symbolic constant and so on.

Ex:- X2 , PI , Sigma

  • Variable

It is an identifier or a name which is used to refer a value.

It is written with a combination of letters, numbers and special character with first letter being alphabet (Underscore & Dollar) also.

Ex:- C , fact , b33 , total_amount

  • Data type

In javascript we do not have to specify type of variable.

“Var” can hold any type of data like string , number , boolean etc

Primitive data types:

Data TypeDescription
Stringrepresents sequence of characters e.g. “hello”
Numberrepresents numeric values e.g. 100
Booleanrepresents boolean value either false or true
Undefinedrepresents undefined value
Nullrepresents null i.e. no value at all

Non-Primitive data types:

Data TypeDescription
Objectrepresents instance through which we can access members
Arrayrepresents group of similar values
RegExprepresents regular expression
  • Declaring Variable

var roll;

roll= name;

Here ‘roll’ is the variable name and ‘name’ is assigning value to variable.

If a variable is declared without a value then its value will be undefined.

Important points in Javascript:-

  • Statements are executed one by one as they are written.
  • Javascripts program and statements are often called Javascripts code.
  • Semicolons separates javascript statements.
  • Ending statement with semicolon is not required but it is highly recommended.
  • Javascript ignores multiple spaces.
Joydeep M
Latest posts by Joydeep M (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x