Java Script Basic

In this blog I am going to discuss some important and basic concepts of Java Script.

Let’s see one by one;

In JavaScript we declare variable using var keyword; we may assign the variable or we may not.

Key Capsule 1:-

So what happen when we declared

var name;

Capsule 1:- Here name stores by default undefined;

if we print using console.log(name)

o/p :- undefined.

Key Capsule 2:-

var name=”Surya”

    var name;

console.log(name)

What you think what will be the out put ?

O/P :- “Surya”

Capsule 2 :- In java script although I declare the variable once again it won’t loose the value.

Key Capsule 3:-

var result=”sun”+2+3;

console.log(result)

result=2+3+”sun”;

console.log(result)

what you think what is the out put ???

O/p:- “sun”23

5”sun”

Capsule 3:- In java script if any numeric values comes after the string then the Plus (+) operator work like as a concatenation operator where as if the numeric value comes before the string then plus (+) operator works and it show addition of number then it concatenate the string.

Key Capsule 4:-

var studnetName=”Suryakant”;

var studentName=”Rajanikant” ;

console.log(studentName);

var studnetName=”Rahul”;

var studentname=”Raj”;

console.log(studnetName);

console.log(studentname);

What will be the out put ??

O/P:- “Rajanikant”

“Rahul”

“Raj”

Capsule 5:- Why so ?? Because the JavaScript variable are case sensitive; so when I write studnetName and strudnetname both are different variable.

Remember all variable in JavaScript are called as identifier and each variable is an unique identifier.

Key Capsule 6 :-

How to print a string like this;

“The name is “Surykant”; he is a blogger.”

I want to print suryakant with the double quot.

To do this in javascript we have different escape character which can be use to achieve this.

We can write;

var data=”The name is \”Suryakant\”; he is a blogger”.

Same for single quto;

var data=”It\’s looking good.”

Most Important Key Capsule 7:-

Difference between == and === operator

“== “ operator is used to check directly the value where as “===” equality operator check the equality and types.

See bellow examples;

Test Case 1:-

var x=”surya”;

var y= “surya”;

console.log(x==y)

console.log(x===y)

o/p- true

Note :- Here the output true for both the case because both are storing same value and both are of same type

Test Case 2:-

var x=”surya”

var y=new string (“surya”)

console.log(x==y);

o/p- true

Scenario:- Here some of us might think that why it returns true ?

This question also came to my mind; because the second one is reference type; as we know inside reference type variable it stores the address of that value i.e “surya”.

So how both are equal then ??

Here important thing to understand that what actually happen when we comparing the value using double equality operator (“==”).

When we using double equality operator (“==”) to compare then this operator perform a type conversion while comparing two things; so in the above example when we compare x and y, although y is a object type it is converted to string type while comparing so both are get same type with value so it returns as true.

Where as triple equality operator (“===”)  never do any type of conversion while comparing; it only check the type and value if both are same then it returns true other wise returns false.

Key To Remember :– So if we check any two reference/object type variable using triple equality operator (“===”) then it always return false; same for double equality operator (“==”) also return false; but if both are reference type pointing to same location then “===” operator return true.

Confused ????

Let’s clear; both reference type/object type pointing to same location means;

var obj=new string(“surya”);

var obj1=obj

Now if we check; obj===obj then we get output as true.

Capsule 7 :- What we learn form the above :-

Double equality operator(“==”) do conversion before checking while triple equal to operator(“===”) never do any conversion before checking it just check the type and value.

examples :-

var a=1;

var b=”surya”;

var c=new string(“surya”);

Now; a===a   // True ;   b===b // True;  c===c   //True

Again if i declare a new object type variable;

var d=new string(“surya”);

Now;  c===d  // False

Note :- Although ‘c’ and ‘d’ are the same type still it return false because after checking the type it will check the value inside it; both are pointing to different location so both have different value so it return false.

if we write; c==d

Note :- Now what happened both are converted to reference type; and due to both pointing different location; so it return false.

Key To Remember :- Due to the above reason double equality operator (“==”) called as loose equality operator where as triple equality operator (“===”) called as  strict equality operator.

Test Case 3:-

var x=”surya”

var y=new string (“surya”)

console.log(x===y);

o/p:- false

Note :- Here the output is false because “===” operator is used to check type and both having different types so it return false.

Test Case 4:-

var x=new string(“surya”);

var y=new string (“surya”);

console.log(x==y);

o/p:- false

console.log(x===y)

o/p:- false

What is value type and reference type in JavaScript ?

Ans:- In java script data types are classified into two types such as value type and reference type.

Under value type we have data type like;

Int, string,number,Boolean,null and etc.

Where as under reference type we have data type like;

Function,array,object.

Combine this all we said all these are object type.

Note:- Value types are directly stored value in side the variable where as reference type are stored the address of the object and that address pointing to the actual value location.

Key Capsule 8 :

In Java script we have different global methods for Number such as;

  • Number()
  • parseInt()
  • parseFloat()

Important Test Case:-

Test Case 1 :- parseInt(“10 Year”) //O/P- 10

Test Case 2 :- parseInt(“Year 10”) //O/P – NaN

Key Capsule 9:-

In JavaScript we can define an array by using bellow syntax;

Var stdArr=[];

Note:- stdArr is a special type of object which store different type of object inside it.

Join Method in Array:-

In JavaScript the join method is used to convert the array into string but we can specify separator inside join method.

For eg:- var arr=[“Ram”,”Hari”,”Madhu”]

arr.join(“*”);

so the o/p Ram * Hari * Madhu.

Key Capsule 10:-

In JavaScript we use a key word called as “use strict”.

This is indicate that we can not use a variable without declaring it. So if we use a variable without declaring it then it’s gives you an error.

Note :- Use strict can be write at the top of the script.

Use strict

a=2+3;

console.log(a) // Error because we did not declare the variable a.

 

Hope above concept helps you in understanding the basic concept; will see more on coming days.

Thanks for reading; have your feedback in comment box if you have any doubt in any test case.

#Share2Know #Learn Basic #JavaScript

 

 

Advertisements

C# 7.0 Features

C# language some Keys to know:

1. In C# language to know the which dot net version you are using at run time you can use “Enviourment.Version”.
You can also find;
Console.WriteLine(Environment.Version);
Console.WriteLine(Environment.OSVersion);
Console.WriteLine(Environment.ProcessorCount);
Console.WriteLine(Environment.MachineName);

2. C# 7.0 Features :-
— 1. Touples:-
— 2. Tuple Deconstruction :- Any object can be deconstructed by defining a Deconstruct method in the class:
for example :-
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }

public void Deconstruct(out string firstName, out string lastName)
{
firstName = FirstName;
lastName = LastName;
}
}

var person = new Person { FirstName = “John”, LastName = “Smith” };
var (localFirstName, localLastName) = person;

In this case, the (localFirstName, localLastName) = person syntax is invoking Deconstruct on the person.

— An alternative approach for the Person class is to define the Name itself as a Tuple. Consider the following:

Example:- class Person
{
public (string First, string Last) Name { get; }

public Person((string FirstName, string LastName) name)
{
Name = name;
}
}

Then you can instantiate a person like so (where we can take a tuple as an argument):

var person = new Person((“Jane”, “Smith”));

var firstName = person.Name.First; // “Jane”
var lastName = person.Name.Last; // “Smith”

— Touple Intialization :-

You can also arbitrarily create tuples in code:

var name = (“John”, “Smith”);
Console.WriteLine(name.Item1);
// Outputs John

Console.WriteLine(name.Item2);
// Outputs Smith

When creating a tuple, you can assign ad-hoc item names to the members of the tuple:

var name = (first: “John”, middle: “Q”, last: “Smith”);
Console.WriteLine(name.first);
// Outputs John

 

— 3. Out var declaration

The out var declaration is a simple feature to improve readability. It allows a variable to be declared at the same time that is it passed as an out parameter.

A variable declared this way is scoped to the remainder of the body at the point in which it is declared.

In C# 7.0, you can inline the declaration of the variable passed to the out parameter, eliminating the need for a separate variable declaration:-

Example :-

if (int.TryParse(input, out var value))
{
Foo(value); // ok
}
else
{
Foo(value); // value is zero
}

Foo(value); // still ok, the value in scope within the remainder of the body

If some of the parameters that a function returns in out is not needed you can use the discard operator _.

p.GetCoordinates(out var x, out _); // I only care about x

An out var declaration can be used with any existing function which already has out parameters. The function declaration syntax remains the same, and no additional requirements are needed to make the function compatible with an out var declaration. This feature is simply syntactic sugar.

Another feature of out var declaration is that it can be used with anonymous types.
7.0
Example:-
var a = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var groupedByMod2 = a.Select(x => new
{
Source = x,
Mod2 = x % 2
})
.GroupBy(x => x.Mod2)
.ToDictionary(g => g.Key, g => g.ToArray());
if (groupedByMod2.TryGetValue(1, out var oddElements))
{
Console.WriteLine(oddElements.Length);
}

In this code we create a Dictionary with int key and array of anonymous type value. In the previous version of C# it was impossible to use TryGetValue method here since it required you to declare the out variable (which is of anonymous type!). However, with out var we do not need to explicitly specify the type of the out variable.

 

Find live frequency of Character in string using Java Script.

In this blog i am going to show you a simple program where you find frequency of character in a string using JavaScript.

Note:- Before starts this simple demo i believe that you must have basic knowledge on JavaScript.

Let start;

To do this demo first we need to design a simple web page where we have one textbox where we need to enter some text and we find the frequency accordingly.

In this example bellow all the functionality are defined inside JavaScript function called as “GetFrequency()

 

<html>
<head>
<meta name=”viewport” content=”width=device-width” />
<title>TestKey</title>
</head>
<body>

<h2>Get Frequency of Character from a string</h2>

Enter Your Text :

 </body>

</html>

<scripts>

var charkey = “”;
function GetTheKey(e) {
charkey = document.getElementById(“txtData”).value.substring(document.getElementById(“txtData”).value.length – 1);
}
function GetFrequency(e) {
debugger
var count = 1;
var value = document.getElementById(“txtData”).value;
if (e.which <= 90 && e.which >= 48) {
var checkCount = 0;
var keyChar = e.key;
if (value.length > 1) {
for (var i = 0; i < value.length – 1; i++) {
if (keyChar == value[i]) {
count++;
}
else
continue;
}

if (count > 1) {
for (var i = 1; i < count; i++) {
if (i != count) {
if (document.getElementById(keyChar + i) != null) {
var eleData = document.getElementById(keyChar + i).innerHTML.replace(/.$/, count);
document.getElementById(keyChar + i).innerHTML = eleData;
checkCount++;
}
}
}
}
if (checkCount == 0) {

var lable = document.createElement(“lable”);
lable.textContent = “The frequency of character ” + keyChar + ” is ” + count;
lable.id = keyChar + count;
document.getElementById(“result”).appendChild(lable);
var br = document.createElement(“br”);
document.getElementById(“result”).appendChild(br);
}
checkCount = 0;
count = 1;
}
else {
var lable = document.createElement(“lable”);
lable.textContent = “The frequency of character ” + keyChar + ” is ” + 1;
lable.id = keyChar + count;
document.getElementById(“result”).appendChild(lable);
var br = document.createElement(“br”);
document.getElementById(“result”).appendChild(br);
count = 1;
}
}
else if (e.which == 8) {
// if (document.getElementById(“txtData”).selectionStart != 0) {

if (document.getElementById(“result”).lastChild != null) {
var ele = document.getElementById(“result”).lastChild;
document.getElementById(“result”).lastChild.remove();
if (document.getElementById(“result”).lastChild != null) {
var iNum = document.getElementById(charkey + count).innerHTML.substring(document.getElementById(charkey + count).innerHTML.length – 1);
if (parseInt(iNum) > 1) {
var eledata = document.getElementById(charkey + count).innerHTML.replace(/.$/, iNum – 1);
document.getElementById(charkey + count).innerHTML = eledata;
document.getElementById(“result”).appendChild(ele);
}
else {
document.getElementById(“result”).lastChild.remove();
}
}
}
}
//}

}

</scripts>

Note:- Do copy and paste above code and remove the last character ‘s’ from script tag.

Any thing not work for you feel free to drop a comment in the comment box; always happy to listen your feedback.

Happy Coading 🙂

#Share2Know @SURYAN_Mode

 

IT Industry Journey.

A Few word about my IT Experience and some career advice what I learned.

IT Journey!!!

Greeting all of You !!!

I have completed 4.7 year in IT industry, apart from that working on many Dot Net Developer Community since last 4 years with providing on-line training many Dot Net Developer Pro on various Dot Net Technology.
Yes it’s true that; It’s an beginning of my IT career more year to go now.
So friends I am not an Tech Guru or Tech Expert to advice you; but yes i can tell you
what i learn in my career in this small amount of time.

I started my career as a .Net Developer in a company called as Focussoftnet and I worked there for 4.7 year. I resigned that company recently and going to start my IT Journey in another MNC company.

I learned many things in this company; special thanks to my Project Manager and our VP for their advice and support; always heartily thanks to Azizur Reheman (PM) for all time support and giving best suggestion and showing a right path, also giving me always R&D type of Task.
I really thankful sir for your faith and believe over me and giving such type of challenging work; as a fresher you know well it’s difficult for me to complete it; but i really happy that you giving me that task as an opportunity to use all my knowledge and ideas, yes it took time to complete but due to your support and giving me time i made all this possible.

These are few bellow points what i learned in this year of experience;

If You are a Fresher Joining to any Company What You do :-

1. As you are fresher it means you required to work on any technology what company gives you.

Tips To Remember:- Here keep in mind always that if you are although a fresher and you did specialized in any technology which company required today; for eg:.Net,Java,PHP and etc then you can apply for that company where you matched your technology; so that you are 90% sure that you are going to work on that technology what you already have specialized. May be you are thinking why 90% not 100% Right ???
Yes Not 100% because you are fresher; so keep in mind if company don’t have any project currently on that particular technology then you required to work on what you get. So set up your mind like that and be flexible.

Their is a way to avoid this 10% too. The idea is before apply the Job first check the Job description clearly what they mentioned and if you all round then in HR round Just clarify once again what technology i am going to work and tell what specialized you have; so many case you get the same technology what you have specialized. So don’t bother about this 10%; just focus on your technology.

2. Once you joined in a company as fresher then don’t think that you can get work on project immediately. Actually it’s differ company to company. Yes you got work immediately if company has running project.
In my career i see many of us frustrated
that i am not getting work; just i am going to office and coming back; also not getting the work what i needed.
May be many of us face same problem; i have also face the same; but i utilize my time on different way without frustrated. The best thing i need to say what i followed; if company won’t giving you work immediately then start learning by your own. Start to practice the concepts. Their are lots of project at Github you can just download it and start doing by your self; otherwise start Google on a particular topic then you get lots of resource on that to read.
If you think you already have all the knowledge with you and you required work to do then the best thing i can suggest that their are lots of open source project available at Github; you just need to login and start contributing your ideas inside that project. Now you might think that what is my benefit??
Right ??
Yes; First of all you get some new ideas and knowledge as well as more importantly people in community going to recognize you if you are a good contributor .In IT industry you required a good connection over all type of people around the globe. As a fresher if you started contributing your ideas inside the project then in very few time you might well recognized inside the community which helps you a lot in your IT Journey.
If you start your career as a Software Developer then you should required to have the art of Self Learning; this only helps you in life long.

Note :- If you need more details about this how can you contribute? for all type of query i am always available and happy to help you. You find all details of me here..

3. Do your task first what given to you; if you finish the task before the time then just inform to your reporting manger; Yes you need to inform not sit ideal why so ???
Because you are joined as a fresher keep in mind to build up your image and make recognize between many employee you should tell so that you create a positive view in front of your Reporting manger.

Now you might think what was it’s advantage ?
You got confirmation very quickly and the hike also good :). Here i am not saying it this happen to all company but yes it true many company treats you as good employee.

4. Don’t be show more your talent.
Yes you should say what you have asked; not say more then that.If you understand the environment and you think your view is required then tell.
Key Point :- Build up Your image through your work not by saying in word.
You only know to whom over you can show your talent show your talent when required and get value of this.

5.Build a good relationship To Everyone :-
As you joined as fresher keep respect to everyone and make yourself more flexible. If any body wants your help share your ideas.
Key Point :- Always make your self update and share the new thing with other and make a good connection among all.

6. Don’t go on your believe always goes on what is the realty.
If you goes on your believe and think yourself it may be like that;
for eg: A task given to you and the task is not clear to you while it is giving; so don’t imagine your self that the task would be like that; do not do this just go and ask once again who ever giving you.
Key Point :- Do not be heighted to ask; if you get fear to ask then you can not rectify the mistake and waste you time. So ask as many time you won’t understand the task. If you ask then only it crate a confidence with in you and the team lead who is giving you task he get positive attitude to-wards you.

Lastly thanks to All My Team Member whom with I worked on.

I really miss the work environment and all of You Guys !!

Hope to See you soon Guys !!

Hope You like this article and it helps you on your way in IT Life.

Share your valuable comments.

 

Suryakanta Nayak,  Software Engineer
SuryakantaN@Solutionsoftware.com
 – Health Plan Partner of the Year

#Share@Know

 

 

Code snippet for search manually using JavaScript.

In web application development we have requirement for implementing of search data from a bulk of data. In this post we are going to see the code snippet for how to implement search functionality by using Java Script..

Download the complete project from here