Javascript Language Assignment Samples

Language

Javascript

1.

The subprograms in JavaScript are packaged into classes. One can create a class and use it along with its member functions, member variables. Subprograms are used to implement a higher level of code, it makes the understanding easier and is used and there are many usages of it in a single program.

Example:

class store{

            var size;

store(nSize){

            this.size = nSize;

}

}

Here store is a subprogram that can be used in the program later.

2.

The parameters in JavaScript are passed by value, it doesn’t support passing by reference. The functions only get to know the values and not their locations.

The JavaScript function supports all in, out, input parameters. On can add a parameter, use it in the calculation and also can return a value.

In parameter is the read-only type.

Out parameter is write-only type.

Inout parameter has both read-write types.

3.

JavaScript is not a statically typed language. One needs to check manually the type of parameters used in the function. One can use write a generic subprograms, for example:

Generic function fun(val1:int, val2:boolean): string{

if(val2){

return string(val1);

}else{

return “true”;

}

}

 

4.

If no argument is passed to the function during the call. Then the parameter has a default value of undefined. One can set default values to the arguments same as most of the languages. The position of the parameter matter in JavaScript. The first formal parameter is matched to the first actual parameter.

Example:

function func(a , b =1){

            return a + b;

}

var c = func(2);

 

5.

Yes, JavaScript doesn’t allow normal overloading mechanism. But there are different ways around which one can do the same task as overloading depending upon the complexity of the work.

This is not allowed in JavaScript, it will just take the last defined function.

function addOne(){ .. }

function addOne(a){ .. }

JavaScript supports overriding.

Example:

new Date(); //default JavaScript Date() method

//override JavaScript Date() method

function Date(){

this.date = "Overriding the date constructor in Date class”;

};

 

6.

Subprograms in JavaScript don't have any effect, as all the parameters are passed by value. So it does matter if the parameters are in or out type.

7.

The return statement in JavaScript, stops the execution of the function and returns the value, to the lhs of the assignment statement which called this function.

 

JavaScript doesn’t support multiple return values but one can use array and other object to return multiple values.

Example:

function func(val1, val2){

            Var ret = [];

            ret.push(val1);

            ret.push(val2);

return ret;

}

JavaScript function does not return using reference.

Example:

function fun(a){

a = 5;

return a;

}

var a = 10;

var b = fun(a);

//This will not change the value of variable a.

 

8.

Yes JavaScript supports recursion.

Example:

function fun(val){

if(val > 0){

print(val);

}else{

fun(val-1);

}

}

fun(3);

JavaScript recursion function can be optimized by using ‘use strict’ in the code.

Example

‘use strict’;

function fac(n, tot=1){

            if(n == 0){

            return tot;

}

return fac(n-1, n*tot);

}

 

9.

JavaScript supports both first-class functions and higher order functions.

Example for usage of higher order function map:

const arr = [1, 2, 3];

const arr2 = arr.map(function(arg) {

            return arg*arg;

}

Some other examples of higher-order functions are filter, reduce.

 

10.

Yes, JavaScript supports nested functions.

Example:

function fun1(a){

            functio            n fun2(b){

            return b*b;

}          

            return fun2(a);

}

You may also like similar pages such as Java Assignment Help, Programming Language Assignment

References: 

[1]Overriding in JavaScript | Learn the Types of Overriding in JavaScript. EDUCBA. (2020). Retrieved 20 May 2020, from https://www.educba.com/overriding-in-javascript/.

[2]Recursion in Functional JavaScript — SitePoint. Sitepoint.com. (2020). Retrieved 20 May 2020, from https://www.sitepoint.com/recursion-functional-javascript/.

[3]Always pass one argument to your JavaScript function. Medium. (2020). Retrieved 20 May 2020, from https://levelup.gitconnected.com/always-pass-one-argument-to-your-javascript-function-4140d909937e.

 

No Need To Pay Extra
  • Turnitin Report

    $10.00
  • Proofreading and Editing

    $9.00
    Per Page
  • Consultation with Expert

    $35.00
    Per Hour
  • Live Session 1-on-1

    $40.00
    Per 30 min.
  • Quality Check

    $25.00
  • Total

    Free

New Special Offer

Get 25% Off

best-assignment-experts-review

Call Back