Home >Web Front-end >JS Tutorial >Some problems encountered in detecting the existence of variables in JavaScript_javascript skills

Some problems encountered in detecting the existence of variables in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:16:10986browse

When writing JavaScript programs, you often need to detect whether a certain variable exists. This is a very simple task, but you will encounter some problems if you are not careful. There are some main points:

1. Ordinary variables

Copy code The code is as follows :



2. Object properties
Copy code The code is as follows:



There is no need to use typeof to detect the properties of the object.

3. When adding attributes to objects, you will also encounter similar problems
Copy code The code is as follows:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn