From novice to JAVA SCRIPT for all

Rapid Javascript Training (Pluralsight) :-

https://jsfiddle.net/hanumesh/sqmb4o5b/1/

1) var total = 5.1 + 3.3
     console.log (total);
output :-
 8.399999999999999


========================================================================
http://javascriptissexy.com/oop-in-javascript-what-you-need-to-know/

Various ways to create an object:-

1) ubiquitous object literal pattern :-
var myObj = {name: "Richard", profession: "Developer"};
2) You can use the prototype pattern, adding each method and property directly on the object’s prototype :-

 function Employee() {
  Employee.prototype.firstName = "Hanumesh";
};
var hanu = new Employee()
console.log (hanu.firstName);

3) You can also use the constructor pattern, a constructor function (Classes in other languages, but Functions in JavaScript). 

function Employee1(name, age) {
  this.name = name;
  this.age = age;
};
var hanu = new Employee1("Hanumesh", "27")
console.log (hanu.name, hanu.age);

====================================================================
Encapsulation in JavaScript :-

function User (theName, theEmail) {

this.name = theName;
this.email = theEmail;
this.quizScores = [];
this.currentScore = 0;
}
--------------​
User.prototype = {
constructor: User,
saveScore:function (theScoreToAdd) {
this.quizScores.push(theScoreToAdd)
},
showNameAndScores:function () {
var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet";
return this.name + " Scores: " + scores;
},
changeEmail:function (newEmail) {
this.email = newEmail;
return "New Email Saved: " + this.email;
}
}
-----------------
firstUser = new User("Richard", "Richard@examnple.com");
firstUser.changeEmail("RichardB@examnple.com");
firstUser.saveScore(15);
firstUser.saveScore(10);
firstUser.showNameAndScores(); //Richard Scores: 15,10​​​//

===============================================

Inheritance in JavaScript

(The Best Pattern: Parasitic Combination Inheritance)

Prototypal Inheritance by Douglas Crockford

============================================
Prototype :-

First, every JavaScript function has a 
prototype property (this

property is empty by default)
Why is Prototype Important and When is it Used?


1) Prototype Property:- Prototype-based Inheritance

 __proto__ “pseudo” property (an alternative syntax) that allows you

to access an object’s prototype property



2) Prototype Attribute:-  Accessing Properties on Objects

The prototype attribute is normally referred to as the prototype

object
, and it is set automatically when you create a new object


=======================================

this in javascript :-

 it refers to an object;

         







Mozilla developer Javascript :-

http://geekswithblogs.net/shaunxu/archive/2013/12/12/bind-call-and-apply-in-javascript-function.aspx


With "bind()" method, we can set the context of a function. So in the future we can invoke this function variant without specifying the context when invoked.
By using "bind" we can set any object as the context of a function. This gives us extremely flexibility to extend our code. I

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide

1) JavaScript is a dynamically typed language. That means you don't have to specify the data type of a variable when you declare it, and data types are converted automatically as needed during script execution

2) Falsy values
The following values evaluate to false (also known as Falsy values):
  • false
  • undefined
  • null
  • 0
  • NaN
  • the empty string ("")
3) Copy an Array:-


var shallowCopy = fruits.slice(); // this is how to make a copy
// ["Strawberry"]
4) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

5) http://www.w3schools.com/js/js_object_definition.asp

6) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model

http://kenwheeler.github.io/slick/

7) Event Bubbling :-
https://javascript.info/tutorial/bubbling-and-capturing

8) Closures :-
Closures are  functions, that  'remember' the environment in which they were created.

9) http://stackoverflow.com/questions/15455009/javascript-call-apply-vs-bind



OOJ:-


Comments

Popular posts from this blog

Set up your VOIP based SIP soft phone and know more about VOIP

Front End Developer Interview quiestions- All in single blog

Data Science v/s Data engineer v/s Data Analyst