Use Bracket Notation to Find the Nth Character in a String

Опубликовано: 07 Май 2026
на канале: HighTech6839v
45
1

What is Bracket Notation in JavaScript? Bracket notation is another way to access a property of an object. To use bracket notation, write the name of the object, followed by brackets [] . Inside the brackets, write the property name as a string. Bracket notation, unlike dot notation, can be used with variables.

To get nth character in String, you can use String's charAt() method. chatAt() method accepts index as an argument and return the character at the given index. If index is out of bound for string, charAt() method returns empty String.

What is const in JavaScript? The const declaration creates block-scoped constants, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration).

What is var in JavaScript? The var statement declares a variable. Variables are containers for storing information. Creating a variable in JavaScript is called "declaring" a variable: var carName; After the declaration, the variable is empty (it has no value).