Warning: file_put_contents(aCache/aDaily/post/brogrammist/--): Failed to open stream: No space left on device in /var/www/tgoop/post.php on line 50
Brogrammist@brogrammist P.35
BROGRAMMIST Telegram 35
`string.charAt(i)` vs `string[i]`

String'dagi bitta simvolni string[index] yoki string.charAt(index) usulida olish mumkin. Agar index'imiz [0, `string.length - 1`] oralig'ida bo'lsa, bu 2 usulning bir biridan farqi yo'q.

Lekin, index'imiz "boshqachaoq" qiymat bo'lsachi? 🤔

Tekshiramiz:

'hello'[NaN]; // undefined
'hello'.charAt(NaN); // 'h'

'hello'[undefined]; // undefined
'hello'.charAt(undefined); // 'h'


Demak, [NaN] bilan holat mantiqan olinsa to'g'ri.

Lekin .charAt(NaN) 'chi? Bu yerda nima bo'lyapti?

Albatta "type coercion"! Ya'ni biz bergan qiymat bilvosita songa, Number'ga aylanib ketyapti:

undefined -> 0
charAt(undefined) -> charAt(0)



Shunday ekan, agar mana bunday qilsak kodimiz kutilgan natijani beradi:

'hello'.charAt('00') // 'h'
👍3



tgoop.com/brogrammist/35
Create:
Last Update:

`string.charAt(i)` vs `string[i]`

String'dagi bitta simvolni string[index] yoki string.charAt(index) usulida olish mumkin. Agar index'imiz [0, `string.length - 1`] oralig'ida bo'lsa, bu 2 usulning bir biridan farqi yo'q.

Lekin, index'imiz "boshqachaoq" qiymat bo'lsachi? 🤔

Tekshiramiz:


'hello'[NaN]; // undefined
'hello'.charAt(NaN); // 'h'

'hello'[undefined]; // undefined
'hello'.charAt(undefined); // 'h'


Demak, [NaN] bilan holat mantiqan olinsa to'g'ri.

Lekin .charAt(NaN) 'chi? Bu yerda nima bo'lyapti?

Albatta "type coercion"! Ya'ni biz bergan qiymat bilvosita songa, Number'ga aylanib ketyapti:

undefined -> 0
charAt(undefined) -> charAt(0)



Shunday ekan, agar mana bunday qilsak kodimiz kutilgan natijani beradi:

'hello'.charAt('00') // 'h'

BY Brogrammist


Share with your friend now:
tgoop.com/brogrammist/35

View MORE
Open in Telegram


Telegram News

Date: |

Commenting about the court's concerns about the spread of false information related to the elections, Minister Fachin noted Brazil is "facing circumstances that could put Brazil's democracy at risk." During the meeting, the information technology secretary at the TSE, Julio Valente, put forward a list of requests the court believes will disinformation. SUCK Channel Telegram Some Telegram Channels content management tips Select “New Channel” Members can post their voice notes of themselves screaming. Interestingly, the group doesn’t allow to post anything else which might lead to an instant ban. As of now, there are more than 330 members in the group.
from us


Telegram Brogrammist
FROM American