From 8f29c5334f10cd90835b8c8b68059d6b05cdbfd1 Mon Sep 17 00:00:00 2001 From: SolidRenner <213125854+SolidRenner@users.noreply.github.com> Date: Sun, 8 Jun 2025 00:55:37 -0500 Subject: [PATCH 1/2] Added new term Strings.raw(). --- .../concepts/strings/terms/raw/raw.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 content/javascript/concepts/strings/terms/raw/raw.md diff --git a/content/javascript/concepts/strings/terms/raw/raw.md b/content/javascript/concepts/strings/terms/raw/raw.md new file mode 100644 index 00000000000..a08a1349f45 --- /dev/null +++ b/content/javascript/concepts/strings/terms/raw/raw.md @@ -0,0 +1,38 @@ +--- +Title: '.raw()' +Description: 'Used to get the raw string form of template literals.' +Subjects: + - 'Web Development' + - 'Computer Science' +Tags: + - 'Strings' + - 'Methods' +CatalogContent: + - 'paths/front-end-engineer-career-path' +--- + +## Syntax + +``` +String.raw(strings, sub1, sub2 /*... */ subN) + +String.raw`templateString` +``` + +- `strings` is a well-formed template literal array object. +- `Sub1,...,subN` Contains substitution values. +- `templateString` is a template literal. + +## Example + +```js +String.raw`Hi\n${name}!`; +//Returns 'Hi //${name}!`, the dollar sign is escaped; ther's no interpolation. +``` + +## Codebyte Example + +```codebyte/javascript +String.raw`Hi\n${2 + 3}!`; +//Returns 'Hi\n5!' +``` \ No newline at end of file From af4d6db894d9a548dce25a6e67f1a3e189e33d43 Mon Sep 17 00:00:00 2001 From: SolidRenner <213125854+SolidRenner@users.noreply.github.com> Date: Sun, 8 Jun 2025 01:31:14 -0500 Subject: [PATCH 2/2] Delete valueOf.md --- .../concepts/strings/terms/valueOf/valueOf.md | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 content/javascript/concepts/strings/terms/valueOf/valueOf.md diff --git a/content/javascript/concepts/strings/terms/valueOf/valueOf.md b/content/javascript/concepts/strings/terms/valueOf/valueOf.md deleted file mode 100644 index 42b7b2f1f75..00000000000 --- a/content/javascript/concepts/strings/terms/valueOf/valueOf.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -Title: '.valueOf()' -Description: 'Returns the value of a String object as a string.' -Subjects: - - 'Web Development' - - 'Computer Science' -Tags: - - 'Functions' - - 'Methods' - - 'Objects' - - 'Strings' -CatalogContent: - - 'introduction-to-javascript' - - 'paths/front-end-engineer-career-path' ---- - -The **`.valueOf()`** method returns the [primitive](https://www.codecademy.com/resources/docs/javascript/data-types) value of a `String` object, similar to the `.toString()` method. Usually, this method is called internally by JavaScript. - -> **Note:** Objects that are descendants of the `Object` class, including `String`s, inherit the `.valueOf()` method. - -## Syntax - -```js -stringObject.valueOf(); -``` - -The `.valueOf()` method takes no parameters. - -## Example - -All primitive string values are wrapped in a `String` object (`new String(value)`). In the following example, this primitive value is returned by the `.valueOf()` method: - -```js -const name = new String('Bill'); -console.log(name); -console.log(name.valueOf()); -``` - -This will print the following: - -```shell -[String: 'Bill'] -Bill -``` - -## Codebyte Example - -Although the `.valueOf()` method is typically invoked internally by JavaScript, it can be used by calling it on a `String` object: - -```codebyte/javascript -const animal = 'cat'; -console.log(animal === animal.valueOf()); - -console.log('apple'.valueOf() === 'apple'); -```