Basic JavaScript Exercises

Question 01

Create a function as a variable (function expression) that prints ‘Hello World’ to console and another function which accepts a variable. The argument passed to the second function should be executed as a function inside the body. Call the second function passing the first function as the argument. Check the output.


Question 02

 Declare a global variable named "vehicleName in the window object.

 Declare a method named printVehicleName to print out the vehicle name .

 Declare an object named Vehicle(using object literal notation) which have a variable called vehicleName and declare a function named getVehicleName and assign it with the printVehicleName  Execute the printVehicleName function and the getVehicleName functions to see the results.

Correct the getVehicleName to print out the global variable vehicleName using the this keyword.

Question 03

Create a separate function using JavaScript closure which accepts the tax percentage and returns a function which accepts the amount and returns the amount after adding tax percentage. Try adding tax percentage to

‘this’ object and check if it works.

Question 04

Write a function to call GitHub API (https://api.github.com/users) and get users and return the users to the caller



ANSWERS FOR THE ABOVE QUESTIONS ARE GIVEN BELOW











0 comments:

Post a Comment