YouTube Icon

Interview Questions.

Top 30 Javascript Objects Interview Questions - Jul 26, 2022

fluid

Top 30 Javascript Objects Interview Questions

Q1. What Is Javascript Date Object?

The Date item is a datatype constructed into the JavaScript language. Date gadgets are created with the new Date( ) as shown under.

Once a Date object is created, some of methods permit you to operate on it. Most methods in reality permit you to get and set the year, month, day, hour, minute, 2d, and millisecond fields of the item, the use of either local time or UTC (standard, or GMT) time.

The ECMAScript widespread calls for the Date object as a way to represent any date and time, to millisecond precision, within one hundred million days earlier than or after 1/1/197@This is a number plus or minus 273,785 years, so JavaScript can constitute date and time till the yr 275755.

Syntax: You can use any of the following syntaxes to create a Date object using Date() constructor.

New Date( )

new Date(milliseconds)

new Date(datestring)

new Date(year,month,date[,hour,minute,second,millisecond ])

Q2. What Are String Methods?

Here is a listing of the methods to be had in String object at the side of their description.

CharAt(): Returns the man or woman at the desired index.

CharCodeAt(): Returns quite a number indicating the Unicode value of the individual on the given index.

Concat(): Combines the textual content of  strings and returns a brand new string.

IndexOf(): Returns the index inside the calling String object of the first occurrence of the specified fee, or -1 if no longer determined.

LastIndexOf(): Returns the index within the calling String object of the final prevalence of the specified cost, or -1 if no longer located.

LocaleCompare(): Returns a variety of indicating whether or not a reference string comes before or after or is similar to the given string in sort order.

Fit(): Used to match a normal expression towards a string.

Replace(): Used to discover a suit among a normal expression and a string, and to update the matched substring with a new substring.

Search(): Executes the look for a fit between a everyday expression and a special string.

Slice(): Extracts a phase of a string and returns a brand new string.

Break up(): Splits a String object into an array of strings via keeping apart the string into substrings.

Substr(): Returns the characters in a string starting at the specified region through the specified quantity of characters.

Substring(): Returns the characters in a string among two indexes into the string.

ToLocaleLowerCase(): The characters within a string are converted to decrease case at the same time as respecting the current locale.

ToLocaleUpperCase(): The characters within a string are transformed to upper case while respecting the modern-day locale.

ToLowerCase(): Returns the calling string value converted to decrease case.

ToString(): Returns a string representing the required item.

ToUpperCase(): Returns the calling string fee converted to uppercase.

ValueOf(): Returns the primitive cost of the required item.

Q3. What Are Array Methods?

Here is a listing of the techniques of the Array object at the side of their description.

Concat(): Returns a brand new array produced from this array joined with other array(s) and/or price(s).

Each(): Returns real if each detail in this array satisfies the provided trying out function.

Filter out(): Creates a brand new array with all of the elements of this array for which the supplied filtering characteristic returns genuine.

ForEach(): Calls a characteristic for every element in the array.

IndexOf(): Returns the first (least) index of an element in the array identical to the desired fee, or -1 if none is observed.

Join(): Joins all elements of an array right into a string.

LastIndexOf(): Returns the final (greatest) index of an element inside the array equal to the specified value, or -1 if none is discovered.

Map(): Creates a brand new array with the outcomes of calling a supplied characteristic on each detail on this array.

Pop(): Removes the final detail from an array and returns that element.

Push(): Adds one or greater elements to the quit of an array and returns the brand new length of the array.

Reduce(): Apply a function simultaneously towards  values of the array (from left-to-right) as to lessen it to a unmarried price.

ReduceRight(): Apply a feature concurrently towards two values of the array (from right-to-left) as to lessen it to a unmarried value.

Reverse(): Reverses the order of the elements of an array -- the primary becomes the final, and the remaining will become the first.

Shift(): Removes the first element from an array and returns that detail.

Slice(): Extracts a phase of an array and returns a new array.

Some(): Returns authentic if as a minimum one element on this array satisfies the furnished testing function.

ToSource(): Represents the source code of an item

type(): Sorts the factors of an array

splice(): Adds and/or gets rid of elements from an array.

ToString(): Returns a string representing the array and its elements.

Unshift(): Adds one or more elements to the front of an array and returns the brand new duration of the array.

Q4. What Is User-described Objects?

User-Defined Objects: All person-described gadgets and built-in objects are descendants of an object known as Object.

The new Operator: The new operator is used to create an instance of an item. To create an object, the brand new operator is observed by the constructor approach.

In the subsequent example, the constructor methods are Object(), Array(), and Date(). These constructors are built-in JavaScript features.

Var employee = new Object();

var books = new Array("C++", "Perl", "Java");

var day = new Date("August 15, 1947");

The Object() Constructor: A constructor is a characteristic that creates and initializes an object. JavaScript presents a special constructor characteristic called Object() to construct the object. The go back price of the Object() constructor is assigned to a variable.

The variable includes a reference to the brand new item. The residences assigned to the item aren't variables and aren't described with the var keyword.

Example 1: Try the following example; it demonstrates the way to create an Object.

<html>

   <head>

      <title>User-defined gadgets</title>

      

      <script type="text/javascript">

         var book = new Object();   // Create the object

         ebook.Subject = "Perl"; // Assign homes to the object

         e-book.Author  = "Mohtashim";

      </script>

      

   </head>

   

   <body>

   

      <script type="text/javascript">

         document.Write("Book call is : " + book.Subject + "<br>");

         report.Write("Book author is : " + book.Creator + "<br>");

      </script>

   

   </body>

</html>

Q5. What Is The 'with' Keyword?

The ‘with’ keyword is used as a type of shorthand for referencing an object's houses or techniques.

The object distinct as a controversy to with turns into the default object in the course of the block that follows. The houses and techniques for the item may be used without naming the item.

Syntax: The syntax for with item is as follows --

with (object)

   houses used with out the object name and dot

 

Q6. What Are Regular Expressions And Regexp Object?

A ordinary expression is an item that describes a pattern of characters.

The JavaScript RegExp elegance represents ordinary expressions, and each String and RegExp define methods that use normal expressions to perform powerful pattern-matching and seek-and-update functions on textual content.

Syntax: A normal expression will be defined with the RegExp () constructor, as follows −

var sample = new RegExp(sample, attributes);

or truly

var sample = /pattern/attributes;

Here is the description of the parameters:

sample − A string that specifies the pattern of the normal expression or every other normal expression.

Attributes − An optionally available string containing any of the "g", "i", and "m" attributes that designate global, case-insensitive, and multiline fits, respectively.

Q7. What Is Javascript Strings Object?

The String object lets you paintings with a chain of characters; it wraps Javascript's string primitive facts kind with a number of helper methods.

As JavaScript routinely converts between string primitives and String objects, you could name any of the helper techniques of the String object on a string primitive.

Syntax: Use the following syntax to create a String item −

var val = new String(string);

The String parameter is a series of characters that has been properly encoded.

Q8. What Is Date Properties?

Here is a list of the homes of the Date item along with their description.

Constructor: Specifies the function that creates an object's prototype.

Prototype: The prototype assets lets in you to feature residences and methods to an object.

Q9. What Are The Math Methods?

Here is a list of the strategies related to Math item and their description

abs(): Returns absolutely the fee of various.

Acos(): Returns the arccosine (in radi) of a variety of.

Asin(): Returns the arcsine (in radi) of more than a few.

Atan(): Returns the arctangent (in radi) of a number.

Atan2(): Returns the arctangent of the quotient of its arguments.

Ceil(): Returns the smallest integer extra than or same to various.

Cos(): Returns the cosine of a variety of.

Exp(): Returns EN, wherein N is the argument, and E is Euler's regular, the base of the natural logarithm.

Ground(): Returns the biggest integer much less than or equal to various.

Log(): Returns the herbal logarithm (base E) of a range of.

Max(): Returns the largest of zero or greater numbers.

Min(): Returns the smallest of 0 or more numbers.

Pow(): Returns base to the exponent electricity, that is, base exponent.

Random(): Returns a pseudo-random wide variety among zero and @

round(): Returns the cost of a number rounded to the closest integer.

Sin(): Returns the sine of a variety of.

Sqrt(): Returns the rectangular root of quite a number.

Tan(): Returns the tangent of quite a number.

ToSource(): Returns the string "Math".

Q10. What Are Date Methods?

Here is a listing of the strategies used with Date and their description.

Date(): Returns ultra-modern date and time

getDate(): Returns the day of the month for the required date consistent with nearby time.

GetDay(): Returns the day of the week for the required date in line with nearby time.

GetFullYear(): Returns the yr of the desired date consistent with nearby time.

GetHours(): Returns the hour in the precise date according to nearby time.

GetMilliseconds(): Returns the milliseconds inside the distinct date in keeping with nearby time.

GetMinutes(): Returns the mins within the targeted date in line with neighborhood time.

GetMonth(): Returns the month inside the targeted date in keeping with neighborhood time.

GetSeconds():Returns the seconds within the exact date  in step with neighborhood time.

GetTime(): Returns the numeric price of the specified date because the number of milliseconds seeing that January 1, 1970, 00:00:00 UTC.

GetTimezoneOffset(): Returns the time-area offset in mins for the cutting-edge locale.

GetUTCDate(): Returns the day (date) of the month inside the specified date in line with normal time.

GetUTCDay(): Returns the day of the week inside the particular date in step with well-known time.

GetUTCFullYear(): Returns the year within the certain date consistent with general time.

GetUTCHours(): Returns the hours in the unique date in step with prevalent time.

GetUTCMilliseconds(): Returns the milliseconds within the unique date according to time-honored time.

GetUTCMinutes(): Returns the mins within the targeted date in line with typical time.

GetUTCMonth(): Returns the month in the exact date consistent with familiar time.

GetUTCSeconds(): Returns the seconds inside the targeted date in line with commonplace time.

GetYear(): Deprecated - Returns the yr in the precise date in keeping with neighborhood time. Use getFullYear instead.

SetDate(): Sets the day of the month for a detailed date according to local time.

SetFullYear(): Sets the overall year for a unique date in keeping with nearby time.

SetHours(): Sets the hours for a specific date in keeping with local time.

SetMilliseconds(): Sets the milliseconds for a distinctive date in line with neighborhood time.

SetMinutes(): Sets the minutes for a certain date in keeping with local time.

SetMonth(): Sets the month for a exact date in keeping with nearby time.

SetSeconds(): Sets the seconds for a exact date in step with neighborhood time.

SetTime(): Sets the Date item to the time represented by way of some of milliseconds for the reason that January 1, 1970, 00:00:00 UTC.

SetUTCDate(): Sets the day of the month for a detailed date in line with usual time.

SetUTCFullYear(): Sets the overall year for a specific date in line with ordinary time.

SetUTCHours(): Sets the hour for a targeted date in keeping with prevalent time.

SetUTCMilliseconds(): Sets the milliseconds for a special date in step with conventional time.

SetUTCMinutes(): Sets the mins for a unique date in line with general time.

SetUTCMonth(): Sets the month for a precise date according to typical time.

SetUTCSeconds(): Sets the seconds for a particular date according to typical time.

SetYear(): Deprecated - Sets the yr for a specific date according to nearby time. Use setFullYear as a substitute.

ToDateString(): Returns the "date" portion of the Date as a human-readable string.

ToGMTString(): Deprecated - Converts a date to a string, using the Internet GMT conventions. Use toUTCString rather.

ToLocaleDateString(): Returns the "date" portion of the Date as a string, the usage of the modern-day locale's conventions.

ToLocaleFormat(): Converts a date to a string, the usage of a format string.

ToLocaleString(): Converts a date to a string, the use of the cutting-edge locale's conventions.

ToLocaleTimeString(): Returns the "time" part of the Date as a string, using the modern-day locale's conventions.

ToSource(): Returns a string representing the source for an equal Date item; you can use this value to create a brand new item.

ToString(): Returns a string representing the specified Date item.

ToTimeString(): Returns the "time" portion of the Date as a human-readable string.

ToUTCString(): Converts a date to a string, using the generic time conference.

ValueOf(): Returns the primitive fee of a Date item.

Q11. What Are String Properties?

Here is a listing of the residences of String item and their description.

Constructor: Returns a reference to the String function that created the item.

Duration: Returns the length of the string.

Prototype: The prototype assets lets in you to feature residences and techniques to an object.

Q12. What Are The Number Methods?

The Number item consists of best the default methods which can be a part of every item's definition.

ToExponential(): Forces a range of to show in exponential notation, even supposing the variety is in the variety wherein JavaScript generally makes use of fashionable notation.

ToFixed(): Formats various with a specific number of digits to the right of the decimal.

ToLocaleString(): Returns a string price version of the modern wide variety in a format that could range consistent with a browser's nearby settings.

ToPrecision(): Defines how many general digits (such as digits to the left and right of the decimal) to display of a range of.

ToString(): Returns the string illustration of the range's price.

ValueOf(): Returns the range's value.

Q13. What Are The Math Properties?

Here is a list of all the homes of Math and their description.

E : Euler's consistent and the base of natural logarithms, approximately 2.7@

LN2: Natural logarithm of two, approximately zero.Sixty nine@

LN10: Natural logarithm of 10, about 2.Three@

LOG2E: Base 2 logarithm of E, approximately 1.Forty four@

LOG10E: Base 10 logarithm of E, approximately 0.43@

PI: Ratio of the circumference of a circle to its diameter, approximately three.1415@

SQRT1_2: Square root of 1/2; equivalently, 1 over the square root of two, approximately zero.7@

SQRT2: Square root of 2, approximately 1.4@

Q14. What Is Javascript Objects?

JavaScript is an Object Oriented Programming (OOP) language. A programming language can be known as item-oriented if it affords 4 basic skills to builders −

Encapsulation − the capability to keep related data, whether or not facts or strategies, together in an item.

Aggregation − the functionality to keep one object inside some other object.

Inheritance − the capability of a class to depend on every other elegance (or variety of instructions) for a number of its properties and methods.

Polymorphism − the capability to jot down one characteristic or method that works in a spread of various methods.

Objects are composed of attributes. If an characteristic contains a function, it's miles taken into consideration to be a technique of the item, otherwise the characteristic is taken into consideration a property.

Q15. What Are Array Properties?

Here is a list of the houses of the Array object together with their description.

Constructor: Returns a reference to the array characteristic that created the object.

Index: The belongings represents the 0-based index of the fit within the string

enter: This property is simplest present in arrays created with the aid of ordinary expression suits.

Period: Reflects the wide variety of elements in an array.

Prototype: The prototype assets lets in you to feature residences and techniques to an object.

Q16. What Is Javascript Math Object?

The math object affords you residences and strategies for mathematical constants and functions. Unlike different global gadgets, Math is not a constructor. All the residences and techniques of Math are static and may be called via the usage of Math as an item with out creating it.

Thus, you confer with the regular pi as Math.PI and also you call the sine feature as Math.Sin(x), in which x is the approach's argument.

Syntax: The syntax to call the houses and techniques of Math are as follows

var pi_val = Math.PI;

var sine_val = Math.Sin(30);

Q17. What Are String Html Wrappers?

Here is a list of the techniques that go back a replica of the string wrapped internal an appropriate HTML tag.

Anchor(): Creates an HTML anchor this is used as a hypertext target.

Big(): Creates a string to be displayed in a huge font as if it had been in a tag.

Blink(): Creates a string to blink as though it have been in a tag.

Ambitious(): Creates a string to be displayed as bold as if it had been in a tag.

Constant(): Causes a string to be displayed in constant-pitch font as if it were in a tag

fontcolor(): Causes a string to be displayed in the specific coloration as if it have been in a tag.

Fontsize(): Causes a string to be displayed inside the designated font length as if it had been in a tag.

Italics(): Causes a string to be italic, as if it have been in an tag.

Link(): Creates an HTML hypertext link that requests every other URL.

Small(): Causes a string to be displayed in a small font, as if it were in a tag.

Strike(): Causes a string to be displayed as struck-out textual content, as though it were in a tag.

Sub(): Causes a string to be displayed as a subscript, as though it were in a tag

sup(): Causes a string to be displayed as a superscript, as if it were in a tag

Q18. Defining Methods For An Object?

The previous examples exhibit how the constructor creates the object and assigns residences. But we need to complete the definition of an item by means of assigning techniques to it.

Example: Try the following instance; it suggests how to add a function along side an item.

<html>

   <head>

   <title>User-defined objects</title>

   

      <script type="text/javascript">

         // Define a feature as a way to paintings as a method

         feature addPrice(quantity)

            this.Fee = quantity; 

         

         

         feature ebook(identify, author)

            this.Identify = name;

            this.Author  = creator;

            this.AddPrice = addPrice; // Assign that method as assets.

         

      </script>

      

   </head>

   <body>

   

      <script type="text/javascript">

         var myBook = new e-book("Perl", "Mohtashim");

         myBook.AddPrice(one hundred);

         

         record.Write("Book identify is : " + myBook.Identify + "<br>");

         document.Write("Book writer is : " + myBook.Author + "<br>");

         report.Write("Book charge is : " + myBook.Price + "<br>");

      </script>

      

   </body>

</html>

Q19. What Are The Javascript Native Objects?

JavaScript has several integrated or native gadgets. These gadgets are available everywhere to your application and could paintings the same manner in any browser walking in any running gadget.

Here is the listing of all vital JavaScript Native Objects −

JavaScript Number Object

JavaScript Boolean Object

JavaScript String Object

JavaScript Array Object

JavaScript Date Object

JavaScript Math Object

JavaScript RegExp Object

Q20. What Are Quantifiers?

The frequency or function of bracketed character sequences and single characters can be denoted by means of a special individual. Each special individual has a particular connotation. The +, *, ?, and $ flags all comply with a person series.

P+: It fits any string containing one or greater p's.

P*: It suits any string containing 0 or extra p's.

P?: It matches any string containing at most one p.

PN: It suits any string containing a sequence of N p's

p2,three: It matches any string containing a sequence of two or 3 p's.

P2, : It suits any string containing a sequence of at least two p's.

P$: It suits any string with p on the cease of it.

^p: It suits any string with p at the start of it.

Q21. What Are The Number Properties?

Here is a list of every belongings and their description.

MAX_VALUE: The largest viable value a variety of in JavaScript can have 1.7976931348623157E+308

MIN_VALUE: The smallest possible fee a range of in JavaScript could have 5E-324

NaN: Equal to a price that is not more than a few.

NEGATIVE_INFINITY: A fee that is much less than MIN_VALUE.

POSITIVE_INFINITY: A cost that is greater than MAX_VALUE

prototype: A static belongings of the Number item. Use the prototype assets to assign new properties and strategies to the Number object in the modern-day report

constructor: Returns the feature that created this item's example. By default that is the Number item.

Q22. What Are The Boolean Properties?

Here is a list of the residences of Boolean object:

constructor: Returns a connection with the Boolean feature that created the item.

Prototype: The prototype assets permits you to add properties and methods to an item.

Q23. What Is Javascript Boolean Object?

The Boolean item represents  values, either "actual" or "false". If cost parameter is disregarded or is 0, -zero, null, fake, NaN, undefined, or the empty string (""), the object has an preliminary price of fake.

Syntax: Use the subsequent syntax to create a boolean item.

Var val = new Boolean(cost);

Q24. What Is Javascript Arrays Object?

The Array object lets you keep multiple values in a single variable. It stores a fixed-size sequential collection of factors of the equal kind. An array is used to keep a group of data, but it's far regularly more useful to think of an array as a collection of variables of the equal type.

Syntax: Use the following syntax to create an Array object:

var fruits = new Array( "apple", "orange", "mango" );

The Array parameter is a listing of strings or integers. When you specify a unmarried numeric parameter with the Array constructor, you specify the initial duration of the array. The maximum length allowed for an array is four,294,967,295.

You can create array via absolutely assigning values as follows:

var culmination = [ "apple", "orange", "mango" ];

You will use ordinal numbers to get right of entry to and to set values internal an array as follows.

End result[0] is the primary detail

end result[1] is the second one element

end result[2] is the 1/3 element

Q25. What Are Object Properties?

Object homes may be any of the three primitive facts kinds, or any of the summary facts types, inclusive of another object. Object residences are commonly variables that are used internally within the object's methods, but also can be globally seen variables which are used.

The syntax for including a assets to an item is:

objectName.ObjectProperty = propertyValue;

For example − The following code gets the record name using the "title" belongings of the record object.

Var str = file.Identify;

Q26. What Are Boolean Methods?

Here is a listing of the strategies of Boolean object and their description.

ToSource(): Returns a string containing the source of the Boolean item; you could use this string to create an equal item.

ToString(): Returns a string of both "proper" or "false" relying upon the value of the item.

ValueOf(): Returns the primitive value of the Boolean item.

Q27. What Are Date Static Methods?

In addition to the many instance strategies indexed previously, the Date object also defines two static techniques. These techniques are invoked thru the Date() constructor itself.

Date.Parse( ): Parses a string illustration of a date and time and returns the inner millisecond illustration of that date.

Date.UTC( ): Returns the millisecond illustration of the desired UTC date and time.

Q28. What Is Object Methods?

Methods are the features that allow the object do some thing or allow something be executed to it. There is a small difference among a feature and a method – at a characteristic is a standalone unit of statements and a method is attached to an item and may be referenced through the this keyword.

Methods are beneficial for the whole thing from showing the contents of the item to the display screen to performing complex mathematical operations on a set of neighborhood properties and parameters.

For example − Following is a easy example to show how to use the write() approach of document object to write down any content material at the document.

Document.Write("This is test");

Q29. What Is Javascript Number Object?

The Number item represents numerical date, both integers or floating-point numbers. In wellknown, you do no longer want to worry approximately Number gadgets because the browser routinely converts wide variety literals to times of the quantity class.

Syntax: The syntax for growing a number item is as follows:

var val = new Number(quantity);

In the region of number, in case you offer any non-quantity argument, then the argument cannot be converted into various, it returns NaN (Not-a-Number).

Q30. What Are Brackets?

Brackets ([]) have a special meaning while used inside the context of ordinary expressions. They are used to find a variety of characters.

[...]: Any one man or woman between the brackets.

[^...]: Any one character not between the brackets.

[0-9]: It fits any decimal digit from zero via @

[a-z]: It fits any person from lowercase a via lowercase z.

[A-Z]: It matches any person from uppercase A via uppercase Z.

[a-Z]: It suits any character from lowercase a thru uppercase Z.

The levels proven above are trendy; you could additionally use the range [0-3] to healthy any decimal digit starting from zero via three, or the range [b-v] to fit any lowercase character starting from b through v.




CFG