JS & jQuery

1. How many type of Objects and Types in Java Script?

There are 4 types of Object as below.

Intrinsic objects   - Date ,String .number,.....
Host Objects - Window ,document
Creating Objects -  var obj =new Object();
Activex Object

The type of all objects created with a custom constructor is object. There are only six types in JavaScript:
object, function, string, number, boolean, and undefined.

2. How will you send a model from jQuery to C# model?

   $("#updateUserPreference").click(function () {
        var userLocale = $("#ddlUserLocale").val();
        var userTimeZone = $("#ddlUserTimeZone").val();
       var  userPreferenceModel = {
            LocaleCode: userLocale,
            TimeZoneId: userTimeZone
       var Id = $("#userId").val();
            type: 'POST',
            contentType: 'application/json; charset=utf-8',  // not datatype:json
            url: updateUserPreferences,
            cache: false,
                    userId: Id,
                    localeCode: $("#ddlUserLocale").val()
            success: function (response) {
                var objectData = vkbeautify.json(response);
                if (successFx) {
            error: function (jqXHR, textStatus) {
                $("#session-error").html("Request failed: " + textStatus).show();

3. What is Object and in how many ways can you create object?
In JavaScript, almost "everything" is an object.
  • Booleans can be objects (or primitive data treated as objects)
  • Numbers can be objects (or primitive data treated as objects)
  • Strings can be objects (or primitive data treated as objects)
  • Dates are always objects
  • Maths are always objects
  • Regular expressions are always objects
  • Arrays are always objects
  • Functions are always objects
  • Objects are objects
There are many ways to create objects.
var book = {
    price: somePrice * discount,
    pages: 500,
    pricePerPage: this.price / this.pages
using new keyword.

var person = new Object();
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;

using an Object Constructor

function person(first, last, age, eye) {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eye;
var myFather = new person("John""Doe"50"blue");

In Java Script Objects are mutable: They are addressed by reference, not by value.
JavaScript variables are not mutable. Only JavaScript objects.

4. Regex to valid an Email Address.

<input id="forwardMailTo" style="width: 80%;"/>

            <span class="field-validation-error field-validation-valid" id="forwardMailToError" style="margin-left:12%;">EmailErrorMsg</span>

var emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    $('#btnSend').click(function () {
        if (emailRegex.test($("#forwardMailTo").val())) {
            if (!$("#forwardMailToError").hasClass("field-validation-valid")) {
        else {


No comments:

Post a Comment