typeof these points of knowledge, do you understand? _javascript skills

Source: Internet
Author: User
Tags numeric value

Yesterday to play with colleagues, colleagues gave me a code topic, is about typeof, feel very fun, here to share to everyone, by the way consolidate their own typeof knowledge points of the summary. If there is no, please give points and make progress together.

The code is like this:

<! DOCTYPE html>
 
 

So, what do you think the Chrome debugger will print when you run the code?

Please look, the effect chart


Why did this result occur?

First analyze the two null in the above figure


because JavaScript first resolves (hoisting) before executing the code.

What is pre-resolution (hoisting)?

In JavaScript, you can declare multiple var statements at any point in the function, as they do at the top of the function, and give a undefined initial value to the variable that the Var declares. This behavior is called pre-resolution (hoisting).

So, before executing the above code, JavaScript will first parse all of the Var variables (a,b,c) (hoisting) when executing a| | When null, A is undefined, and because it is a | | operation, so the result is null slightly.

c| | Null is a truth.

Again, why would typeof F be undefined? F is not defined, should not be an error?

Yes, if we were to use an undefined variable, the browser would have an error.

However, when you use typeof to determine an undefined variable, you return undefined.

What is the mechanism of the typeof when judging the value type? Summarized as follows:

1. For numeric type values, typeof returns number, noting that Nan is also a numeric type because it represents a special non-numeric value in JavaScript.

2. For string-type values, typeof returns a string.

3. For boolean-type values, typeof returns a Boolean.

4. For objects, arrays, NULL, TypeOf returns object

5, for function type, typeof return function

6. If the OP count is not defined (does not exist or is not assigned), it will return undefined.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.