Found 9150 Articles for Object Oriented Programming

The Pros and Cons of Using Ajax

Ayush Gupta
Updated on 27-Nov-2019 10:35:33

6K+ Views

Ajax is a set of web development techniques using many web technologies on the client-side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.Any other technology Ajax also has its own pros and cons. Let's look at some of those.Pros −Allows applications to render without data and fill data as the application gets it from the server.Gives platform independence to application developersFaster page rendersMore responsive applicationsNo rerenders of whole pages are needed to update only a single area.Cons−Any user whose ... Read More

Safely setting object properties with dot notation strings in JavaScript

Ayush Gupta
Updated on 27-Nov-2019 10:34:36

923 Views

You can use lodash's set method to set properties at any level safely. Setting first-level properties are pretty straightforward. Nested property access is tricky and you should use a tested library like lodash for it.You can set a deeply nested object in the following way −Examplelet _ = require("lodash"); let obj = {    a: {       b: {          foo: "test"       },       c: 2    } }; _.set(obj, "a.b.foo", "test1"); _.set(obj, "a.c", { test2: "bar" }); console.log(obj);OutputThis will give the output −{ a: { b: { foo: 'test1' ... Read More

Safely Accessing Deeply Nested Values In JavaScript

Ayush Gupta
Updated on 27-Nov-2019 10:27:51

390 Views

You can use lodash's get method to get properties at any level safely. Getting first-level properties is pretty straightforward. Nested property access is tricky and you should use a tested library like lodash for it.You can access a deeply nested object in the following way −Examplelet _ = require("lodash"); let obj = {    a: {       b: {          foo: "test"       },       c: 2    } }; console.log(_.get(obj, "a.b.foo")); console.log(_.get(obj, "a.c")); console.log(_.get(obj, "a.test")); console.log(_.get(obj, "a.test.x"));OutputThis will give the output −test 2 undefined undefinedYou can also write your own ... Read More

Accessing nested JavaScript objects with string key

Ayush Gupta
Updated on 27-Nov-2019 10:23:09

2K+ Views

You can use lodash's get method to get properties at any level safely. Getting first-level properties is pretty straightforward. Nested property access is tricky and you should use a tested library like lodash for it.You can access a deeply nested object in the following way −Examplelet _ = require("lodash"); let obj = {    a: {       b: {          foo: "test"       },       c: 2    } }; console.log(_.get(obj, "a.b.foo")); console.log(_.get(obj, "a.c")); console.log(_.get(obj, "a.test")); console.log(_.get(obj, "a.test.x"));OutputThis will give the output −test 2 undefined undefinedYou can also write your own ... Read More

How to Send and Receive JSON Data to and from the Server

Ayush Gupta
Updated on 27-Nov-2019 10:20:22

3K+ Views

JavaScript can send network requests to the server and load JSON. JS does this using something called AJAX. AJAX stands for Asynchronous JavaScript and XML. JS has an API, fetch, to GET(receive) and POST(send) information to the server.You can use fetch to GET JSON data in the following way −Exampleconst URL = 'https://jsonplaceholder.typicode.com/todos/1' // Send a GET request without any data to the server fetch(URL, {method: "GET"}) // Get the JSON data from the raw response    .then(res => res.json()) // Print the result    .then(console.log)OutputThis will give the output −{    "userId": 1,    "id": 1,    "title": "delectus ... Read More

Query-string encoding of a Javascript Object

Ayush Gupta
Updated on 27-Nov-2019 10:16:51

196 Views

The query string is made up of query parameters and used to send data to the server. This part of the URL is optional. It needs to be constructed by the developer. This can be done using a native method called encodeURIComponent.The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the characterUsing the new ES6 format, objects can be query string encoded in the following way −Examplelet obj = {    name: 'John',    age: 25,    city: 'Chicago' ... Read More

How to do string interpolation in JavaScript?

Abdul Rawoof
Updated on 26-Aug-2022 11:56:24

18K+ Views

String interpolation in JavaScript is a process in which an expression is inserted or placed in the string. To insert or embed this expression into the string a template literal is used. By using string interpolation in JavaScript, values like variables and mathematical expressions and calculations can also be added. The template literal has a dollar sign followed by curly brackets. Inside the curly brackets of this template literal, the expression or the mathematical calculation which is to evaluated and embedded should be written. Syntax The syntax of the string interpolation in JavaScript is as follows. `string where interpolation should ... Read More

Advantages and Disadvantages of JavaScript

Abdul Rawoof
Updated on 12-Sep-2023 01:20:55

31K+ Views

JavaScript might be a client-side scripting language, inferring that the client's browser handles ASCII text file processing rather than an online server. With the aid of JavaScript, this can load the webpage without contacting the primary server. For instance, a JavaScript function might verify that all the required fields are filled out on an online form before it is submitted. The JavaScript code has the ability to output an error message before any data is actually sent to the server. Both advantages and disadvantages apply to JavaScript. A client's browser is frequently used to execute JavaScript directly. Similar advantages to ... Read More

What are the differences between lodash and underscore?

Ayush Gupta
Updated on 27-Nov-2019 10:03:22

1K+ Views

lodash and underscore are both utility libraries that make JavaScript easier by providing utils that make working with arrays, numbers, objects, strings, etc. much easier. These libraries are great for −Iterating arrays, objects, & stringsManipulating & testing valuesCreating composite functionsThey are both functional libraries. Lo-Dash is a fork of Underscore, and still follows Underscore’s API enough to allow it to serve as a drop-in replacement. But under the hood, it’s been completely rewritten, and it’s also added a number of features and functions that Underscore does not provide.Lo-Dash was created to provide more consistent cross-environment iteration support for arrays, strings, ... Read More

What is an anonymous function in JavaScript?

Arnab Chakraborty
Updated on 23-Aug-2022 08:13:53

2K+ Views

Like other advanced languages, JavaScript also supports anonymous functions. From the word anonymous, it is clear that when a function has no identifier or no name, that function is called an anonymous function. The only difference between anonymous function and normal function is that normal function has names but anonymous functions do not have any Additionally, anonymous functions are used for simpler and shorter applications which are easier to maintain. In this article, we shall cover what is an anonymous function in JavaScript, how we can use them, their syntax and basic usage as well as advantages and limitations. ... Read More

Advertisements