JavaScript(node.js)

[Mobile version(QRCode)]
Access record[Graph / PV Info.(Past 1 day / Past 1 week) / Access from outside (Yesterday / Past 1 week) / Vistors's list]
ProfilePmail(Mail)
Inbox   /Send   /Sent
Reviews(List   /Limit)
Poll   /Agree:Got   /Sent
Fan
Works/Music
Blog
[Write]
Links
My Play List
 Created dateCategoryArticle title
12017/08/06JavaScript(n..How to check undefined or ..
 Created dateNameRecent messages

1.
2017/08/06 No.4 "JavaScript(node.js) > How to check undefined or null value of JavaScript's object or value"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

1. Problem of checking valid value of JavaScript's object
2. How to install

1. Problem of checking valid value of JavaScript's object

To check the validness of JavaScript's object, you have to write very log description.
Example.
if (typeof geoinfo !== 'undefined' && geoinfo !== null && typeof geoinfo.geometry !== 'undefined' && geoinfo.geometry !== null && typeof geoinfo.geometry.location_type !== 'undefined' && geoinfo.geometry.location_type !== null) {
....
}

You can use @hikarine3/is-defined to check valid value of Javascript's object with ease.
After installation of npm and npm's module of "@hikarine3/is-defined," you can rewrite above sentence like this.

import isDefined from '@hikarine3/is-defined';
if (isDefined(geoinfo, "geometry.location_type")) {
...
}

Quite Simple.
If the tier of object is only 0 or 1, you can write this way.

import isDefined from '@hikarine3/is-defined';
if (isDefined(tier0obj)) {
...
}

import isDefined from '@hikarine3/is-defined';
if (isDefined(tier0obj.tier1)) {
...
}

2. How to install

If you have already installed npm, you can do like this.

npm install @hikarine3/is-defined;

Here is npm and github page.
https://www.npmjs.com/package/@hikarine3/is-defined
https://github.com/hikarine3/is-defined

Add comment to this article
Subscribe to RSS
RSS
Display Style of blog
List/Mobile(QRCode)
Term
Category
All
1.Japan
2.Atlassian's products
3.Self
4.Development of this site
5.Japanese comics
6.Japanese anime
7.Weekly hot news of Japanese culture
8.OP/ED/PV
9.Japanese game
10.Ranking
11.Japanese Comics (Manga)
12.Search Engine
13.Japanese drama
14.Japanese otaku culture
15.Programming
16.Ineternet world
17.Movie
18.C/C++
19.BerkeleyDB
20.Apache programming
21.Spam
22.Meteor
23.Marketing
24.Python
25.Scrum
26.JIRA
27.Git
28.CI
29.Jenkins
30.AWS
31.Operation
32.Singapore
33.Cloud
34.Mysql Cluster
35.DevOps
36.Bitbucket
37.Xamarin
38.Good and new
39.Monitoring
40.node.js
41.React
42.Phillipines
43.Hiring
44.Python
45.SEO
46.Malaysia
47.Mongodb
48.Perl
49.Docker
50.Life hack
51JavaScript(node.js)
52.Dance
53.QA
54.Mysql
55.How to dump only schema
56.How to dump only schema
Sayings from S-Cry-Ed

Rule in this world is speed. Even stupid person can write cool novel if he can spend 20 years for it.

If someone helped me, I will help him in return, which is my rule.

To become stronger, consider what is cowardliest thinking. And rebel against the thinking, which will make you stronger.



I am Japanese but working for some English sites.

Doctor Job Career
Nurse Job Career
Top Page top MetaSeachJP Works