What are the Function and Objects?

What are the Function and Objects?

Posted on

Hello guys, till now I have basic knowledge, and many more topics cover in javascript. If didn’t read or learn this article so click on this link, https://smgplaza.com/category/javascript/.

Now In this article, you can see the Data type, function, object, and this keyword. Also, for this you may learn basic HTML so that prefer this to understand the hole HTML language, so link –  https://techiebot55.blogspot.

Variables can hold many data type : Numbers, Strings, Objects and more.

var l = 16;            // Number
var l1 = "SMGPLAZA";   //String
var l2 = {Name:"SMGPLAZA", Extension:".com"}     //object

Data Type:-

Data Type is important concept. Able to operate on variables,it’s important to know something about the type.

<html>
<body>

<h2>JavaScript</h2>

<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>

<script>
  
var x = 20 + "Line";  // First number and second string both add into one string.
var x1 = "20" + "Line"; // Number treat as a string.
var x2 = 20 + 4 + "line"; // Start with number, 20 and 4 as numbers.Add two number and second string.
var x3 = "line" + 20 + 4; // Start operand with string so after all operands treat as a string.

document.getElementById("demo").innerHTML = x;
document.getElementById("demo1").innerHTML = x1;
document.getElementById("demo2").innerHTML = x2;
document.getElementById("demo3").innerHTML = x3;

</script>

</body>
</html>

Output:-

JavaScript Strings and Numbers:-

A string is a series of characters. It is written in quotes. Two Types: Double and Single quotes. The number can be used with and without decimals. Like var x = 10; or var x = 10.43;

Primitive data:-

primitive data value is a single simple data value with no properties and methods.

The typeof operator can return in primitive data type:-

  • Number
  • String
  • Boolean
  • Undefined

Complex Data:-

Complex Data Type:-

The typeof operator returns “object” for object, array, and null. The operator doesn’t return for function. The typeof operator can return in complex data type:-

  • Function
  • Object

JavaScript Function:-

The javaScript function is a block of code for a particular task. The function is executed when something invokes it. Function defines with the keywords, followed by NAME, followed by PARENTHESES(). The function name can letters, digits, underscores, and dollar signs. Name separated by commas.

Code to be executed by the function placed inside the curly brackets. Parameters are listed inside the parentheses(). Arguments are the values received by the function when it’s invoked. Inside a function, arguments behave as local variables.

Function Invocation:-

Function will execute when something call it for the function.

  • When an event occurs.
  • When it’s a call for the function.
  • Automatically(self invoked)

Function Return:-

Return statement used to stop executing function. The function was invoked from the statement and return to execute the function after the invoke functions. The return value is returned back to the call function. An example is like,

var x = myfun(10, 5);

function myfun(x, y)
{
	return a+b;
}

Output is 15.

JavaScript Objects:-

In function, create an object, Objects are called properties. Access object properties in two ways : objectName.propertyName or objectName[“propertyName”].

An object can also have methods and actions that can be performed on objects.

this keyword:-

this refers to the owner of the function. this.firstName means the firstname property of this object. If you access a method without the parentheses, it’ll return function.

<html>
<body>
<p id="demo"></p>
<script>

var x = {
  Name: "smgplaza",
  Ext : ".com",

  fullName : function() {
    return this.Name + " " + this.Ext;
  }
};
document.getElementById("demo").innerHTML = x.fullName();

</script>
</body>
</html>

Output is like – smgplaza.com

Also, visit these articles:-

If you have any doubts any suggestions or any query DM us one below Social media handles.

Our Social Media Handles:-

Instagram Handle :- https://www.instagram.com/smgplaza/

Twitter Handle :- https://twitter.com/smgplaza

Thank you so much. You have to follow us using your mail id and also follow us on social media for more updates.

Leave a Reply

Your email address will not be published. Required fields are marked *