javascript basics for beginners

Hi This blog is all about javascript basics for beginners which one should know. Its very difficult to carry all the things which we read every day. This javascript basic blog is a knowledge backlog which i would love to share with every individual who’s new or want to refresh the memories 😉 for next milestone of like 😀 .

1. Javascript variable are case sensative

2. Variavle Scope
-variable declared inside functions are local variable
-variable declared outside of function like “if” or “for” loop are global variable by default.

3. javascript function have access to the global variables

4. function: A function is a JavaScript procedure—a set of statements that performs a task or calculates a value.

“function literal notation” for defining the function is as follows.
var f = function(){return 1;}

5. Any object can specify its own properties, either when you create it or at run time.
In addition, any object can be associated as the prototype for another object, allowing the second
object to share the first object’s properties.

6. Javascript Cunstructor : Any JavaScript function can be used as a constructor. You use the new operator
with a constructor function to create a new object.

7. In class-based languages, you typically create a class at compile time and then you instantiate instances
of the class either at compile time or at run time. You cannot change the number or the type of properties
of a class after you define the class. In JavaScript, however, at run time you can add or remove properties of any object.
If you add a property to an object that is used as the prototype for a set of objects, the objects for which it is the prototype also get the new property.

8. Javascript Object Inheritance:

   var person = function () {
	this.name = '';
	this.age = '';
   };
   function male() {
      this.gender = 'male';
   };
   male.prototype = new person;
   function female() {
      this.gender = 'female';
   };
  female.prototype = new person;
  var maleObj = new male;

When JavaScript sees the new operator, it creates a new generic object and passes this new object as the value of the this keyword to the male constructor function.
Now the constructor function explicitly sets the value of the person property, and implicitly sets the value of the internal __proto__ property to the value of
male.prototype. The __proto__ property checks the prototype chain used to return property values.Once these properties are set, JavaScript returns
the new object and the assignment statement sets the variable maleObj to that object.

9. flexible constructors:

   var person = function (name, age) {
	this.name = name || '';
	this.age = age || '18';
   };

10. How to set value for default attribute of parent object in javascript.

function male (name, age) {
  this.base = person;
  this.base(name, 31);
  this.gender = "male";
}
OR
function male (name, age, gender) {
  person.call(this, name, age);
  this.gender = gender || "";
}

11. If you want to change the value of an object property at run time and have the new value be inherited by all descendants of the object
If you want to have default values for object properties and you want to be able to change the default values at run time.
you should set the properties in the constructor’s prototype, not in the constructor function itself
(i.e. Create property using “prototyp”).

12. JavaScript does not support multiple inheritance.

This is part one shall share more details very soon.

Share this nice post:

One thought on “javascript basics for beginners

  1. Hey There. I came across your blog the utilization of msn. This can be
    a really neatly written article. I’ll be certain to bookmark it and return to learn more of
    your useful information. Thanks to the post. I will definitely return.

Comments are closed.