This is the 25th day of my participation in the August Challenge

Persistence in learning, notes is the soul, review the old to learn new, from time to time, review the knowledge point, deepen memory, get twice the result with half the effort!

Earlier we learned about Boolean types in JavaScript

Today we’re going to learn about string objects in JavaScript

JavaScript string object

In JS contains a variety of objects: string object/array object/form object/document object/window object and so on, these objects of various methods can greatly improve the efficiency of our programming, for our program to increase the rich dynamic function.

Today we’re going to look at string objects, one of the basic data types.

1. Create string objects

Strings are familiar, but do you really know anything about strings?

It is also an immutable array in nature, having the same length property as an array.

When operating on a string object, the contents of the string are not changed because the string is frozen when it is created. We can extract substrings from strings, or we can concatenate multiple strings into a new string.

1.1 String.fromCharCodeCreating a string

const my_array = [621.103.49.929.999.Awesome!]
Copy the code

String objects can be created using the function string.fromCharcode, which takes any number of arguments. Access to string elements can be accessed via charCodeAt.

const my_string = String.fromCharCode(... my_array) my_string.charCodeAt(0) = = =621 // --> true
typeof my_string // --> "string"
my_string.length / / -- > 5
Copy the code

The congruence operation === is very useful in string judgment

my_array === my_array // true
my_array === [621.103.49.929.999.Awesome!] // false
my_string === String.fromCharCode(621.103.49.929.999.Awesome!) // true
Copy the code

As shown above, two strings containing the same content will return true when judged by ===, whereas arrays need to come from the same reference to be considered true by ===

1.2 Declare string variables directly

A method that declares a string variable as a string object using the var let const keyword

It is recommended to create the string my_string using double quotation marks and assign to it with =

[var/let/const] Variable name = stringlet my_string = "iwin621"
Copy the code

1.3 new keyword to create a string object

Created by the String constructor String()

[var/let/const] Variable name =new String(String)Copy the code

There is no feeling too troublesome, the front of a direct assignment, more convenient!

String related methods

  • concat
  • slice
  • indexOf
  • lastIndexOf
  • startsWith
  • endsWith
  • contains

Read more

Read more articles please check:

【JS】 Boolean type

[JS] Exception (error) processingtry-catch

Various magical bugs in [JS]

【 Data structure 】 data structure – objects and arrays (2) Array Array, 【 data structure 】 data structure – objects and arrays (1) Object, 【 data structure 】 in-depth understanding of JSON

Node.js file system server – emulated interface

[Node.js] file system module, [Node.js] HTTP module

[Node.js] efficiency tools – NVM & NRM, etc

Node.js Package management tool NPM and YARN

【Node.js】 Build automated development environment – basic introduction

[Node.js] Installation & Documentation, [Tool Preparation], [Start], [Detailed Steps (4)], [Module processing tools (5)], [Understanding of modular programming]

【Github】 Multi-user collaboration (2), 【Github】 Basic use (1)

【Git】 Code version control – Basic Operation (1)

Keep up the pace, step by step! Updates below:

Next will continue to learn JavaScript related methods in detail, chong Duck!! xdm

Learn the efficiency tools to improve development efficiency and empower our development!

Keep up the pace and keep moving forward

Come on!! go~~