Object Oriented Programming in JavaScript

Object Oriented Programming

Object-oriented programming (OOP) is a programming language model organized around objects rather than “actions” and data rather than logic.

Concepts of OOP

  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

Objects

An object is a collection of properties, and a property is an association between a name (or key) and a value. A property’s value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects.

Type of Objects

  • User-defined Objects – These are custom objects created by the programmer to bring structure and consistency to a particular programming task.
  • Native Objects – These are provided by the JavaScript language itself like String, Number, Boolean, Function, Date, Object, Array, Math, RegExp, Error as well as object that allow creation of user-defined objects and composite types.
  • Host Objects – These objects are not specified as part of the JavaScript language but that are supported by most host environments, typically browsers like window, navigator.
  • Document Objects – These are part of the Document Object Model (DOM), as defined by the W3C. These objects presents present the programmer with a structured interface to HTML and XML documents. Access to the document objects is provided by the browser via the document property of the window object (window.document).

Declaration and initialization of Object

  • Using Object Literal

Multiword key required quotation

Declaration and initialization of Object

  • Using Object Literal

Declaration and initialization of Object

  • Using Object Literal

Declaration and initialization of Object

  • Using Object Constructor

Declaration and initialization of Object

  • Using Object Constructor
Tagged : / /

Typeof operator in JavaScripts

The typeof operator is used to get the data type (returns a string) of its operand. The operand can be either a literal or a data structure such as a variable, a function, or an object.

Syntax: –
typeof operand
typeof(operand)

Ex: –
typeof “a”;

Undefined

The undefined type is used for variable or object properties that either do not exist or have not been assigned a value. The only value an undefined type can have is undefined.

Null

The null value indicates an empty value; it is essentially a placeholder that represents “nothing”. The null value is defined as an empty object so using typeof operator on a variable holding null shows its type to be an object.

Undefined Vs Null

Undefined means the value hasn‟t been set, whereas null means the value has been set to be empty.

var, let and const

var – The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for variables declared outside any function, global.

let – let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.

const – This declaration creates a constant whose scope can be either global or local to the block in which it is declared. Global constants do not become properties of the window object, unlike var variables. An initializer for a constant is required; that is, you must specify its value in the same statement in which it’s declared which can’t be changed later.

Tagged : / / / /

Tutorials for PHP Operators

What is Operators in PHP?

Operators are symbols that tell the PHP processor what actions should be taken. The Add (+) sign, for example, instructs PHP to combine two variables or values, but the bigger (>) symbol instructs PHP to compare two values. Don’t make the mistake of assuming that operators and functions are the same. Instead of functional, such operators might be used (such as the PHP ternary).

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Spaceship operators
PHP Operators
Tagged : / / / / / /