PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 9, 2022

[FIXED] What are Hooks in JavaScript and how are they used for by by JavaScript testing frameworks like Mocha?

 July 09, 2022     assertion, import, javascript, keyword, node.js     No comments   

Issue

    I was reading about the Node.js Assertion Class when I was blown back from what I saw -- there was an as operator inside of an import statements destructor-brackets! This surprised for couple of reasons:

  1. For one, I had thought, previously, that the keyword as was a TypeScript reserved word only, and had nothing to do with JavaScript or Node.js, and I am not alone on this. I DuckDuckGo'd the as keyword before authoring this question and got the following StackOverflow question as one of the search results:
  • What does the “as” keyword do?

    Everyone who answered the question above all stated the same thing, "The keyword as is a TypeScript thing". It seems that as being part of Node.js is not very well known yet.

  1. The other reason I was surprised, which leads into my question, had to do with where the as keyword was located, inside of an import statements destructor-brackets, as seen below:

(If you haven't viewed the Node.js link above, you can skip it, below is the use of as that I keep referring to.)

import { strict as assert } from 'assert';

import assert from 'assert/strict';

So what I would like to know is how does the as keyword work in Node.JS? Is it going to have use cases outside of assertions, or is the import statement above a singular use-case?


Solution

as keyword is a part of ES6 module syntax.

You use as when you need to rename the exported named variables/functions in order to avoid conflict between library and your code, or just because you want to rename it XD

You can read more about it here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_an_export_with_a_more_convenient_alias



Answered By - moonlight8978
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing