What does this javascript function do?

var n = {
        Android: /Android/i.test(navigator.userAgent),
        Safari: /iPhone|iPad|iPod/i.test(navigator.userAgent) && !/CriOS|Chrome|Mercury/.test(navigator.userAgent)
    };

I'm interested in learning about the function /Android/i.test (). If this is a function in another file? I guess this is not the case since the following function / iPhone | iPad | iPod / i.test () is even more curious. Is this a string comparison of the string "Android"? Can someone provide me with the documentation?

+4
source share
2 answers

This is a method call for regular expression /Android/i.

The part /Android/iis a regular expression or “regular expression” that is used to match patterns in rows.

, test, true, . , :

androidRegex = /Android/i;
safariRegex = /iPhone|iPad|iPod/i;
criOsregex = /CriOS|Chrome|Mercury/;
var n = {
    Android: androidRegex.test(navigator.userAgent),
    Safari: safariRegex.test(navigator.userAgent) && !criOsregex.test(navigator.userAgent)
};

Javascript - /pattern/flags, pattern - , flags - .

Android : Android, i, .

, "" iPhone, iPad iPod. | .

CriOS, , i, , ( ).

+15

var n two properties, Android Safari.

initialized, , boolean, User Agent Navigator - Android , iPhone, iPad iPod .

, properties true, false.

EDIT. @N3dst4, . . .

0

Source: https://habr.com/ru/post/1623757/


All Articles