<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: John Doe</title>
    <description>The latest articles on DEV Community by John Doe (@s0xzwasd).</description>
    <link>https://dev.to/s0xzwasd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F233944%2F0a9c3301-34a7-4719-9dc4-673c74d8695f.jpg</url>
      <title>DEV Community: John Doe</title>
      <link>https://dev.to/s0xzwasd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/s0xzwasd"/>
    <language>en</language>
    <item>
      <title>First Glance: WSL2 &amp; GoLand on Windows 11</title>
      <dc:creator>John Doe</dc:creator>
      <pubDate>Wed, 06 Oct 2021 18:07:17 +0000</pubDate>
      <link>https://dev.to/s0xzwasd/first-glance-wsl2-goland-on-windows-11-26l4</link>
      <guid>https://dev.to/s0xzwasd/first-glance-wsl2-goland-on-windows-11-26l4</guid>
      <description>&lt;p&gt;Windows 11 was just released a few days ago and GoLand introduces support for projects inside the WSL2 mount and it is available in the &lt;a href="https://www.jetbrains.com/go/nextversion/" rel="noopener noreferrer"&gt;Early Access Program&lt;/a&gt;. It is a good time to get started and combine things for modern Go development step-by-step.&lt;/p&gt;

&lt;p&gt;I will show you a small introduction to configure WSL2 and GoLand, how to install Go SDK and open projects inside WSL2 mounts. First off, we have to install WSL2 under Windows 11. There are a few steps to consider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure WSL2 on Windows 11
&lt;/h2&gt;

&lt;p&gt;First off, we are going to install WSL2 itself via &lt;code&gt;wsl --install&lt;/code&gt; in PowerShell with &lt;em&gt;admin rights&lt;/em&gt;. The operation takes a bit of time and at the end of it, you can see the successful message: &lt;em&gt;The requested operation is successful. Changes will not be effective until the system is rebooted&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I would say that the process of installing WSL2 in Windows 11 is much easier than earlier. One command does all things.&lt;/p&gt;

&lt;p&gt;After that, open Ubuntu distribution (or change to a different one using &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install#change-the-default-linux-distribution-installed" rel="noopener noreferrer"&gt;Microsoft article&lt;/a&gt;), enter username, password and install Go SDK.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Go SDK under WSL2
&lt;/h3&gt;

&lt;p&gt;There are a few ways to install Go SDK:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://golang.org/doc/install" rel="noopener noreferrer"&gt;Official guide&lt;/a&gt; from Go team.&lt;/li&gt;
&lt;li&gt;Go &lt;a href="https://snapcraft.io/go" rel="noopener noreferrer"&gt;snap package&lt;/a&gt; on Ubuntu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I prefer an official guide. It is pretty well documented and easy to start. Pay attention that it requires &lt;em&gt;sudo&lt;/em&gt; privileges for the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget -c https://golang.org/dl/go1.17.1.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few preparations to use it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Specify &lt;code&gt;export PATH=$PATH:/usr/local/go/bin&lt;/code&gt; under &lt;code&gt;$HOME/.profile&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Load &lt;code&gt;$PATH&lt;/code&gt; changes to the current shell session: &lt;code&gt;source ~/.profile&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To confirm that Go is configured properly, we can execute &lt;code&gt;go version&lt;/code&gt; and should get the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go version go1.17.1 linux/amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are good to go to the next section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project opening in GoLand
&lt;/h2&gt;

&lt;p&gt;Let's create our project right from GoLand. On Welcome Screen, select New Project and specify project location under WSL2 mount. You can create directories from the pop-up by right-clicking on the root folder. Make sure that the path to the project contains &lt;code&gt;\\wsl$&lt;/code&gt; prefix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\\wsl$\Ubuntu\home\s0xzwasd\Projects\Go\dev-to-example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwx6qv6hrm1zj8g8hwh6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwx6qv6hrm1zj8g8hwh6.png" alt="An option to create directories in GoLand" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GoLand highlights a warning and requires Go SDK in WSL. We can click on the Plus icon and choose Local, then find Go SDK (&lt;code&gt;\\wsl$\Ubuntu\usr\local\go&lt;/code&gt; by default). Create a project and wait for Go SDK indexing.&lt;/p&gt;

&lt;p&gt;As an example, I take &lt;a href="https://gobyexample.com/interfaces" rel="noopener noreferrer"&gt;Go by Example: Interfaces&lt;/a&gt; code snippet. Let's run it via gutter icons around &lt;code&gt;main()&lt;/code&gt; function. After that, try to debug a bit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wo1ycbak06psplcz24x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wo1ycbak06psplcz24x.png" alt="GoLand runs code from WSL2 mount" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We've configured all necessary environments to get developer things done. 🎉&lt;/p&gt;

&lt;h3&gt;
  
  
  Limitations
&lt;/h3&gt;

&lt;p&gt;So, there are several limitations at the moment, especially symlinks and File Watchers are not supported (&lt;a href="https://youtrack.jetbrains.com/issue/IDEA-253253" rel="noopener noreferrer"&gt;IDEA-253253&lt;/a&gt;, &lt;a href="https://youtrack.jetbrains.com/issue/WEB-38925" rel="noopener noreferrer"&gt;WEB-38925&lt;/a&gt;) as well as External Tools (&lt;a href="https://youtrack.jetbrains.com/issue/IDEA-201045" rel="noopener noreferrer"&gt;IDEA-201045&lt;/a&gt;) and Mozilla RR (&lt;a href="https://github.com/rr-debugger/rr/issues/2506" rel="noopener noreferrer"&gt;GITHUB-2506&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We can use WSL2 and GoLand for Go development for now. It is much easier to get started and separate personal and development environments. As a benefit of Windows 11, we can &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps" rel="noopener noreferrer"&gt;run GUI apps&lt;/a&gt; inside WSL2 and it looks really promising.&lt;/p&gt;

</description>
      <category>go</category>
      <category>windows</category>
      <category>goland</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Run tests with -race flag in GoLand 🏎</title>
      <dc:creator>John Doe</dc:creator>
      <pubDate>Tue, 29 Jun 2021 09:14:06 +0000</pubDate>
      <link>https://dev.to/s0xzwasd/run-tests-with-race-flag-in-goland-512j</link>
      <guid>https://dev.to/s0xzwasd/run-tests-with-race-flag-in-goland-512j</guid>
      <description>&lt;p&gt;To understand &lt;code&gt;-race&lt;/code&gt; flag better, we can refer to the &lt;a href="https://golang.org/doc/articles/race_detector" rel="noopener noreferrer"&gt;Go documentation&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Data races are among the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is easy to use via the command line interface. So, how to use &lt;code&gt;-race&lt;/code&gt; flag in GoLand with tests? Is it possible to use &lt;code&gt;-race&lt;/code&gt; always in tests? Here you go.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add &lt;code&gt;-race&lt;/code&gt; flag to a specific test
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to a test file, click on the gutter icon near the test name and select &lt;em&gt;Modify Run Configuration&lt;/em&gt;. &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56b5m1k7it2w94cndjpm.png" alt="Gutter menu with the Modify Run Configuration entry"&gt;
&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;-race&lt;/code&gt; entry to the &lt;em&gt;Go tool arguments&lt;/em&gt; field. &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhop4mzqpq7h7n54gev93.png" alt="Example of adding race flag"&gt;
&lt;/li&gt;
&lt;li&gt;Save changes and run the configuration again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add &lt;code&gt;-race&lt;/code&gt; flag to all tests
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to &lt;em&gt;Help | Find Action&lt;/em&gt; in the main menu (&lt;em&gt;Shift+Shift&lt;/em&gt; by shortcuts) and type &lt;em&gt;Edit Configurations&lt;/em&gt;, press Enter.&lt;/li&gt;
&lt;li&gt;Select the &lt;em&gt;Edit configuration templates&lt;/em&gt; option, find &lt;em&gt;Go Test&lt;/em&gt;. &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjnc72eu8q140na5mv0d.png" alt="Option is left-bottom position"&gt;
&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;-race&lt;/code&gt; entry to the &lt;em&gt;Go tool arguments&lt;/em&gt; field. Pay attention that changing a template does not affect the existing configuration and you should add the flag manually to the same field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Congratulations! 🎉 Now your tests use &lt;code&gt;-race&lt;/code&gt; flag and you can see warnings from the compiler. &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttbm6s7er6m1o8uqnia8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttbm6s7er6m1o8uqnia8.png" alt="Example of warning from the compiler"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>goland</category>
      <category>go</category>
      <category>tests</category>
      <category>configuration</category>
    </item>
    <item>
      <title>Configure revive Go linter in GoLand</title>
      <dc:creator>John Doe</dc:creator>
      <pubDate>Fri, 05 Mar 2021 11:55:35 +0000</pubDate>
      <link>https://dev.to/s0xzwasd/configure-revive-go-linter-in-goland-2ggl</link>
      <guid>https://dev.to/s0xzwasd/configure-revive-go-linter-in-goland-2ggl</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. Revive provides a framework for development of custom rules, and lets you define a strict preset for enhancing your development &amp;amp; code review processes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s configure &lt;a href="https://revive.run/" rel="noopener noreferrer"&gt;revive linter&lt;/a&gt; and implement it into GoLand. First of all, we need to download the package using &lt;code&gt;go get&lt;/code&gt; action.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

go get -u github.com/mgechev/revive


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, navigate to &lt;code&gt;$GOPATH/bin&lt;/code&gt; and try to execute &lt;code&gt;./revive&lt;/code&gt; to make sure that it works as expected. There is shouldn’t be any errors.&lt;/p&gt;

&lt;p&gt;So, the main advantage of revive is easy configurable configs. Go to our project directory and add a new one. I create &lt;code&gt;config.toml&lt;/code&gt; file with the recommended configuration from &lt;a href="https://revive.run/docs#recommended-configuration" rel="noopener noreferrer"&gt;docs&lt;/a&gt;. Install &lt;a href="https://plugins.jetbrains.com/plugin/8195-toml" rel="noopener noreferrer"&gt;Toml plugin&lt;/a&gt; if you are interested in syntax highlighting.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
[rule.empty-block]
[rule.superfluous-else]
[rule.unused-parameter]
[rule.unreachable-code]
[rule.redefines-builtin-id]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Configuration and installation steps are completed. Now is time to configure &lt;a href="https://www.jetbrains.com/help/go/using-file-watchers.html" rel="noopener noreferrer"&gt;File Watcher&lt;/a&gt; in GoLand.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;File Watcher is a GoLand tool that allows you to automatically run a command-line tool like compilers, formatters, or linters when you change or save a file in the IDE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to the IDE settings (&lt;code&gt;Preferences / Settings | Tools | File Watchers&lt;/code&gt;) and add a new file watcher, select custom template.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fak5wjl6773x16ktgtr5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fak5wjl6773x16ktgtr5l.png" alt="Select &amp;lt;custom&amp;gt; template option"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add a name, e.g. revive linter, then set File type to Go files. Scope option should be Project Files. The next step is to fill out Tool to Run on Changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Program: path to revive linter (&lt;code&gt;$GOPATH/bin&lt;/code&gt;), e.g. &lt;code&gt;/Users/user.name/go/bin/revive&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Arguments: &lt;code&gt;-config config.toml -formatter unix ./…&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-config&lt;/code&gt; path to our config that we created previously.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-formatter&lt;/code&gt; type of formatter. I prefer Unix.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;./..&lt;/code&gt; to check all Go files inside the project directory.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Output path to refresh: empty.&lt;/li&gt;

&lt;li&gt;Working directory: &lt;code&gt;$ProjectFileDir$&lt;/code&gt; macro.&lt;/li&gt;

&lt;li&gt;Environment variables: empty.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Expand Advanced Options and select Show console to Always and select/unselect other checkboxes if needed. The result of the configuration is presented in the screenshot below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xw8dqrotre76axodr0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xw8dqrotre76axodr0m.png" alt="New File Watcher configure settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it. Save changes, then try to create a simple file and save changes. Congrats! 🎉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqw3g26tentnwgkd50m2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqw3g26tentnwgkd50m2b.png" alt="Example of revive inspection"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>goland</category>
      <category>linters</category>
      <category>configuration</category>
    </item>
    <item>
      <title>All about console logging in JavaScript</title>
      <dc:creator>John Doe</dc:creator>
      <pubDate>Sat, 23 May 2020 20:17:35 +0000</pubDate>
      <link>https://dev.to/s0xzwasd/all-about-console-logging-in-javascript-588</link>
      <guid>https://dev.to/s0xzwasd/all-about-console-logging-in-javascript-588</guid>
      <description>&lt;p&gt;In this article I want to collect all the information about logging in the console. Do you want to pump your skill in this and surprise familiar developers? Then let's get started! ✨&lt;/p&gt;

&lt;h2&gt;
  
  
  console.log()
&lt;/h2&gt;

&lt;p&gt;This is probably one of the most frequent commands that we use when debugging the application. However, even this command has chips you may not be aware of. For example, you can pass several arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dev.to&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;protocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;HTTPS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, you can transfer objects, arrays or functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  console.warn() &amp;amp; .error() &amp;amp; .debug() &amp;amp; .info()
&lt;/h2&gt;

&lt;p&gt;This is a very interesting logging feature, which should not be abandoned and can be used daily.&lt;/p&gt;

&lt;p&gt;Some of the most important advantages of using: entities are separated, warnings or errors during logging can be recognized immediately, you can make a filter of the desired type.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvj205l64i3it6m7togj8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvj205l64i3it6m7togj8.png" alt="Alt Text" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  console.warn() ⚠
&lt;/h3&gt;

&lt;p&gt;Using &lt;code&gt;console.warn()&lt;/code&gt;, you can display a warning if something suddenly goes wrong, but, for example, it does not greatly affect the main operation of the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;multiply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ooops. b is less than zero!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  console.error() 🌋
&lt;/h3&gt;

&lt;p&gt;Obvious use: when something seriously went wrong. More informative and immediately visible, unlike &lt;code&gt;console.log()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;concatNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secondName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;secondName&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;secondName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; : console.error('Something goes wrong!');)
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  console.debug() 🐛
&lt;/h3&gt;

&lt;p&gt;It is very convenient to use the application for debugging, since then you can go through the entire code and remove it if you suddenly forgot. 🧹&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Audi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2020&lt;/span&gt;
    &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;132043&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  console.info() ℹ
&lt;/h3&gt;

&lt;p&gt;It can be used to display some kind of reference information, for example, the execution time of a specific code / function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Code executed &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; seconds`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Variables and special values
&lt;/h2&gt;

&lt;p&gt;When using string values, you can specify variables that are declared with the following arguments. Be sure to specify the type of value: string, number, and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, my name is %s and I'm %d years old!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Daniil&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we made two variables with different types: string and number.&lt;/p&gt;

&lt;p&gt;In addition, you can use tabs or newlines. The main thing is not to forget the escape of the character :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;That tabs!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can smoothly switch to using CSS in the console and create beautiful output 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Using CSS in console! 🎨
&lt;/h2&gt;

&lt;p&gt;We came to the most interesting. Using a special directive &lt;code&gt;%c&lt;/code&gt;, you can set CSS properties for a string. Pass the styling itself as the second argument (most styles are supported). Let's look at an example right away.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is %cCSS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;color: aqua&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in the example, «CSS» will be displayed with aqua color.&lt;/p&gt;

&lt;p&gt;Who uses VS Code there is a special extension that will help with this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=rehfres.colored-console-log" rel="noopener noreferrer"&gt;VS Code Extension: Colored Console Log&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Output grouping
&lt;/h2&gt;

&lt;p&gt;For ease of reading the logs, they can be grouped. This will help if you have a large amount of data that can be combined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;That console group!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Info in group #1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupEnd&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  «Assert» values
&lt;/h2&gt;

&lt;p&gt;In short, &lt;code&gt;console.assert()&lt;/code&gt; displays an error message if the statement is false. Let's see an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Foo is not set now&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Assertion failed: Foo is not set now&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stack tracing 🏎
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the console, we get the function call stack in the following order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bar
foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Try it out!
&lt;/h2&gt;

&lt;p&gt;I prepared a small sandbox where you can test all of the listed use cases (grouping in this sandbox is not supported at the time of writing).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/console-advanced-logging-jmiww" rel="noopener noreferrer"&gt;Codesandbox&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will be glad to see examples of your use of logging in the comments :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Using SCSS &amp;&amp; CSS variables in React</title>
      <dc:creator>John Doe</dc:creator>
      <pubDate>Wed, 18 Mar 2020 16:31:09 +0000</pubDate>
      <link>https://dev.to/s0xzwasd/using-scss-css-variables-in-react-322j</link>
      <guid>https://dev.to/s0xzwasd/using-scss-css-variables-in-react-322j</guid>
      <description>&lt;p&gt;Using variables allows you not to remember the «magic» numbers of each value, just declare the variable once and use it throughout the project. This will help in the future, when it will be necessary to change some value, then we will do it in only one place. We can say that this is a CSS on small steroids.&lt;/p&gt;

&lt;p&gt;There are two approaches to organizing variables: using &lt;a href="https://sass-lang.com/" rel="noopener noreferrer"&gt;SASS&lt;/a&gt; (SCSS) and inline CSS variables. We will see both, they are conveniently compatible in the React project. This is my experience that I applied in one of the projects and, as it seems to me, it is convenient. Check out CSS variable support on &lt;a href="https://caniuse.com/#feat=css-variables" rel="noopener noreferrer"&gt;caniuse&lt;/a&gt; (hope you don't have to work with IE11 😅).&lt;/p&gt;

&lt;p&gt;Let's start with an empty sheet, but in order not to configure Webpack from scratch, we will use a very popular solution — &lt;a href="https://github.com/facebook/create-react-app" rel="noopener noreferrer"&gt;create-react-app&lt;/a&gt;. In the console, execute the command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Wait until everything is installed, then go to the project folder and use npm or yarn to install a new dependency for working with SASS and SCSS-syntax.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add node-sass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The last and most boring 😒 thing remained of the preparatory phase: we rename all &lt;code&gt;.css&lt;/code&gt; files to &lt;code&gt;.scss&lt;/code&gt;, do not forget to update the import of these files in the components themselves.&lt;/p&gt;

&lt;p&gt;Everything is behind, we are launching the project, our project should open without errors, but so far there are no changes in it either.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now for the fun part. To work with variables, I create a separate folder in the &lt;code&gt;src&lt;/code&gt; directory, call it &lt;code&gt;design-tokens&lt;/code&gt;. In this folder we create two files: &lt;code&gt;_scss-variables.scss&lt;/code&gt; and &lt;code&gt;css-variables.scss&lt;/code&gt;. As a result, the structure of the project should look something like the screenshot below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk50nsz5ncacfr1c1pdwj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk50nsz5ncacfr1c1pdwj.png" alt="Visual Studio Code: project folders and files in current directory"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Excellent! Do not forget to import these two files into one of the root components, I will have &lt;code&gt;index.scss&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "./design-tokens/scss-variables.scss";
@import "./design-tokens/css-variables.scss";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Most of the path has been covered, very little remains: create variables and understand how to use them. Let's start with the creation.&lt;/p&gt;

&lt;p&gt;A frequent question that arises for those who begin to use variables: what to put into variables, what values ​​and what properties? And there is no definite answer, it all depends on your and team preferences. I can give advice that will give understanding at the initial stage: create color variables, font sizes and names, line-height. This will be enough and save a lot of time in the future.&lt;/p&gt;

&lt;p&gt;Let's start by creating CSS variables first, for this we’ll go to the &lt;code&gt;css-variables.scss&lt;/code&gt; file and create a «root» selector, which will later help us use the variables throughout the project. For example, I will make the color variables of the flag of Germany, in order to further use them as the main color scheme in the project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
  --color-primary: #000000;
  --color-secondary: #DD0000;
  --color-additional: #FFCE00;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Notice how the variables are called. I could name them &lt;code&gt;--color-black&lt;/code&gt;, &lt;code&gt;--color-yellow&lt;/code&gt; and so on, but what if the designer of our project comes and says that now we will use orange instead of yellow? Try to name variables abstractly so that they are responsible for their purpose, rather than expressing a specific entity (for example, a specific yellow color).&lt;/p&gt;

&lt;p&gt;We are done with CSS variables, now you can go into any component styles file and use them. Perhaps I will change the &lt;code&gt;background-color&lt;/code&gt; of the App component in the &lt;code&gt;App.scss&lt;/code&gt; file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.App-header {
  background-color: var(--color-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Wonderful! Now write variables this way throughout the project.&lt;/p&gt;

&lt;p&gt;The question remains: why do we need the &lt;code&gt;_scss-variables.scss&lt;/code&gt; file and how to use it? For myself, I found a solution that I use SCSS variables for indentation and media-queries, since I use them less often and not in all components. For example, in the file, create several variables for margins and paddings.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$spacer-xs: 4px;
$spacer-s: 8px;
$spacer-m: 12px;
$spacer-l: 17px;
$spacer-xl: 28px;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The syntax is slightly different, but the essence is the same, we declared five variables with specific values ​​in pixels. Unlike CSS variables, they are not globally accessible and need to be imported into each file in which we want to use. Import is similar to CSS syntax, I will create the components folder, inside which is the Card folder, where I will add the &lt;code&gt;Card.scss&lt;/code&gt; file. I import variables inside this file. Now I can use both types of variables in one file, which I will do.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "../../design-tokens/scss-variables.scss";

.card {
  background-color: var(--color-secondary);
  margin: $spacer-m;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we have two types of variables that we can use throughout the project and quickly override if necessary. Create, invent new and practice in consolidating the acquired skills, I wish you all productive work!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>javascript</category>
      <category>css</category>
    </item>
  </channel>
</rss>
