Introduction to JS Functions and objects

 

Introduction to JS Functions and objects

Js is known as Java script it is the most popular programming language. It is also known as the web programming language. It is generally easy to learn the language. Now Javascript has various functionalities and objects associated with it. 

Mostly javascript is about objects. Also as discussed javascript is the most vital part in terms of web development. You can even create your objects to encapsulate some related functions. It is discussed in various web development interview questions and answers pdf.

Introduction to javascript Objects

Generally, in javascript, most of the things are objects, from core javascript features like arrays to browsers. You can even go for your objects to encapsulate the various functionalities and variables into efficient packages and generally act like easy to handle data containers. 

There are some examples of the objects in terms of javascript. These are:

  1. Booleans can be considered the javascript objects if they are defined with the new keyword. Similarly, numbers can be objects if defined with the new keyword.
  2. Strings can be objects if defined with the new keywords.
  3. Dates are always objects in Javascript
  4. Math are always objects
  5. Regular expressions are always objects
  6. Arrays are always objects
  7. Functions are always objects
  8. Objects are always objects
  9. All the values in javascript except for the primitives are considered as objects. 

Javascript Primitives

A primitive value is a value that has no properties or methods in general. A primitive data type is the data containing the primitive value. Primitive values are generally immutable as they are hardcoded and cannot be changed. 

Objects are the variables that contain single values.

For example: let person = "Jack Roy";

Javascript variables can also contain various values. Objects are variables too but they can contain more than a single value.

For example: 

let person = {firstName:"Jack", lastName:"Roy", age:40, eyeColor:"black"};

A Javascript object is generally the collection of named values. It is declared using Const Keyword.

For example: 

const person = {firstName:"Jack", lastName:"Roy", age:40, eyeColor:"black"};

Javascript generally defines the five different primitive data types that are:

  1. Number
  2. Null
  3. String
  4. Undefined
  5. Boolean

For example: 

  • Value: "Hello"- Type: string
  • Value: 2.15 - Type: number
  • Value: true - Type: boolean
  • Value: false -Type: boolean
  • Value: null - Type: null 
  • Value: undefined - Type:undefined

Object properties: The named values are known as the object properties.

For example: 

  • Property: Firstname - Value: Jack
  • Property: Lastname - Value: Roy
  • Property: Age - Value: 40
  • Property: Eye color - Value: black

The objects that are generally written in name-value oar are usually similar to that of

  1. Dictionaries that are used in python language.
  2. Hash maps in Java.
  3. Hash Tables in C language.
  4. Associative arrays in java
  5. Hashes in ruby and Perl

Javascript Functions

The javascript function is the block of the code that is designed to perform the particular task. The javascript function is executed when it is called or is evoked. A javascript function is generally defined with the function keyword, followed by the name and the parenthesis.

For example:

function name(parameter1, parameter2, parameter3) 

Also Read: Cybercrime Explanation – Provisions And Hacking

Comments