<?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: alternativeboy</title>
    <description>The latest articles on DEV Community by alternativeboy (@alternativeboy).</description>
    <link>https://dev.to/alternativeboy</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%2F683293%2Fabef2816-6407-4cb2-ae31-820392dd5a4a.jpeg</url>
      <title>DEV Community: alternativeboy</title>
      <link>https://dev.to/alternativeboy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alternativeboy"/>
    <language>en</language>
    <item>
      <title>มาเล่น Tailwind CSS กับ Angular กัน</title>
      <dc:creator>alternativeboy</dc:creator>
      <pubDate>Tue, 22 Feb 2022 07:56:07 +0000</pubDate>
      <link>https://dev.to/alternativeboy/maaeln-tailwind-css-kab-angular-kan-328p</link>
      <guid>https://dev.to/alternativeboy/maaeln-tailwind-css-kab-angular-kan-328p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Tailwind CSS&lt;/strong&gt; คืออะไรกันนะ Tailwind คือ Utility-First CSS Framework ตัวนึงที่จะช่วยทำให้เรา styling element ได้อย่างรวดเร็วโดยที่เราไม่ต้องไม่ต้องไปเขียนคลาสเอง&lt;/p&gt;

&lt;h2&gt;
  
  
  ข้อดี
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;เพื่อป้องกัน ชื่อ class ซ้ำกันกับ parent component เป็นสาเหตุที่ทำให้เกิด style collision&lt;/li&gt;
&lt;li&gt;การ Styling ในโปรเจกต์ก็จะไปในทิศทางเดียวกัน&lt;/li&gt;
&lt;li&gt;ขนาดของ Css ที่ compile ออกมามีขนาดที่เล็กมากๆ ( เดี๋ยวจะเขียนบทความเพิ่มเติมเกี่ยวกับการ optimization ของ Tailwind ว่าเล็กตามคำโฆษณาที่เค้าโม้ไว้รึเปล่า 😂)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;หลังจากที่เกริ่นมาสักพักเรามาเริ่มติดตั้ง Tailwind ใน Angular กัน&lt;/p&gt;

&lt;h2&gt;
  
  
  การติดตั้ง
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ติดตั้ง Angular CLI ด้วย npm หรือ yarn
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// NPM
npm install -g @angular/cli

// Yarn
yarn add @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;สร้างโปรเจกต์ Angular
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-tailwind
cd angular-tailwind
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;ติดตั้ง Tailwind Css ใน project
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// NPM
npm install -D tailwindcss postcss autoprefixer

// Yarn
yarn add tailwindcss

// สร้างไฟล์ Tailwind config
npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;ไปตั้งค่าใน tailwind.config.js ( อยู่ระดับเดียวกับ package.json ) เพิ่ม "./src/*&lt;em&gt;/&lt;/em&gt;.{html,ts}", ใน content
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  content: [
    "./src/**/*.{html,ts}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;เพิ่ม Tailwind ไปใน style ของเรา ( ตรงนี้อาจจะแตกต่างกันถ้าหากเลือก style config ตอนสร้างโปรเจ็ค Angular )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1.1 เลือก Style แบบ CSS&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;1.2 เลือก Style แบบ SCSS หรืออย่างอื่น&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Start build process
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;ลองเล่น Tailwind CSS กัน ให้ลอง copy code ด้านล่างนี้ไปแปะใน app.html ดูว่าออกมาสวยงามไหมถ้าใช่ ขอแสดงความยินดีด้วย เราได้ติดตั้ง Tailwind CSS เรียบร้อยแล้ว แต่ถ้าไม่ Comment มาได้เลยเดี๋ยวมาดูกันว่าติดตรงไหน&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;






&lt;p&gt;แต่เดี๋ยวก่อนนอกจากข้อดีแล้ว ยังก็ยังมีข้อเสียอยู่นะ&lt;/p&gt;

&lt;h2&gt;
  
  
  ข้อเสีย
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ถ้าเราทำงานเป็นทีม อาจจะต้องมีการสื่อสารที่ดีว่าจะเปลี่ยนจากการ styling element แบบที่เคยทำมาเป็นการใช้ Tailwind&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ฝั่ง html ลายตามาก เพราะ styling ทุกอย่างเราเอามาใส่ในฝั่ง html ไม่ได้เขียนแยกเป็น style file ( css, scss หรืออื่นๆ )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;อาจจะต้องใช้เวลาเรียนรู้นิดนึงว่า Design system ของ Tailwind นั้นเป็นยังไงเช่น Color, Spacing, Sizing, Typography และอีกมากมาย&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  สรุป
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS&lt;/strong&gt; ถือว่าเป็นอีกทางเลือกนึงที่เราจะกำจัดปัญหาเรื่อง Style collision แล้วลดเวลาเรื่อง Design system แถมยังลดเวลาในการ styling element อีกด้วย&lt;/p&gt;




&lt;h2&gt;
  
  
  แถม
&lt;/h2&gt;

&lt;p&gt;ติดตั้ง Extension เสริมเพื่อให้ใช้ Tailwind ได้ง่ายขึ้น&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;InteliJ จริงๆ ฝั่ง Jetbrain support อยู่แล้ว แต่ถ้าอยากอ่านละเอียดไปที่ &lt;a href="https://www.jetbrains.com/help/webstorm/tailwind-css.html"&gt;ลิ้งค์&lt;/a&gt; ได้เลย&lt;/li&gt;
&lt;li&gt;VSCode &lt;a href="https://tailwindcss.com/docs/editor-setup#intelli-sense-for-vs-code"&gt;ตามลิ้งค์นี้ได้เลย&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ตามไปดู Code  ได้ที่&lt;/p&gt;

&lt;p&gt;Repository : &lt;a href="https://github.com/kanomtang/angular-tailwind"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tailwindcss</category>
      <category>css</category>
      <category>angular</category>
    </item>
    <item>
      <title>Let's play Tailwind CSS with Angular</title>
      <dc:creator>alternativeboy</dc:creator>
      <pubDate>Tue, 22 Feb 2022 07:46:22 +0000</pubDate>
      <link>https://dev.to/alternativeboy/maaeln-tailwind-css-kab-angular-kan-2i1b</link>
      <guid>https://dev.to/alternativeboy/maaeln-tailwind-css-kab-angular-kan-2i1b</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Tailwind CSS&lt;/strong&gt; Tailwind &lt;strong&gt;CSS&lt;/strong&gt; is a utility-first CSS framework packed with classes for quickly custom user interfaces without creating our classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Prevent classes name of parent and child components are duplicate leads to a style collision problem.&lt;/li&gt;
&lt;li&gt;Make styling elements direction in a project the same way.&lt;/li&gt;
&lt;li&gt;Compile size of a CSS file is smaller than traditional styling ( I will write the articles about optimization Tailwind later, I hope files size are smaller following their advertisement 😂).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After talking about Tailwind, Let's start to install Tailwind to our project!.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Install Angular CLI with npm or yarn.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// NPM
npm install -g @angular/cli

// Yarn
yarn add @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create Angular project.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-tailwind
cd angular-tailwind
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add Tailwind CSS into our project.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// NPM
npm install -D tailwindcss postcss autoprefixer

// Yarn
yarn add tailwindcss

// Create file Tailwind config
npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add some settings in tailwind.config.js ( same level as package.json ) add &lt;code&gt;"./src/**/*.{html,ts}",&lt;/code&gt; in &lt;strong&gt;content&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  content: [
    "./src/**/*.{html,ts}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add Tailwind in our main style sheet ( It is different when you select style config when creating Angular project ).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1.1 Select Style as CSS&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;1.2 Select Style as SCSS or else&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Start build process
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Let's try to apply Tailwind to our HTML code. If you can run the code and its beautiful display on the website congratulations!, you are finished adding Tailwind to the project. But f you are stuck adding Tailwind to our project please let me know in the comment.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;






&lt;p&gt;However, Tailwind CSS still has CONS.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONS
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We need to have good communication among the team. Because we change the way to style elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The styles are mixed in HTML code makes it hard to understand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take time for learning about utility classes of Tailwind such as Color, Spacing, Sizing, Typography, and so on.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Tailwind CSS&lt;/strong&gt; is an alternative way to styling elements and helps eliminate the styling collision problems also reduces time to create a design system and styling elements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;Install extensions for used Tailwind efficiencies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;InteliJ The JetBrains already supported Tailwind CSS. If you want to read more, I provided this &lt;a href="https://www.jetbrains.com/help/webstorm/tailwind-css.html"&gt;link&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;VSCode &lt;a href="https://tailwindcss.com/docs/editor-setup#intelli-sense-for-vs-code"&gt;link&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My code.&lt;/p&gt;

&lt;p&gt;Repository : &lt;a href="https://github.com/kanomtang/angular-tailwind"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If something's wrong, incomplete or you want to share the experience. Please let me know in the comment.&lt;br&gt;
Thank you for taking the time to read this😘.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tailwindcss</category>
      <category>css</category>
      <category>angular</category>
    </item>
    <item>
      <title>Var vs Const vs Let what is different ?</title>
      <dc:creator>alternativeboy</dc:creator>
      <pubDate>Mon, 21 Feb 2022 06:25:52 +0000</pubDate>
      <link>https://dev.to/alternativeboy/var-vs-const-vs-let-what-is-different--2pfn</link>
      <guid>https://dev.to/alternativeboy/var-vs-const-vs-let-what-is-different--2pfn</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; The differences between these three are Scope, Declaration, Update Value and Re-declaration&lt;/p&gt;

&lt;h2&gt;
  
  
  Contents
&lt;/h2&gt;

&lt;p&gt;These three are the way to declare variables in Javascript.&lt;/p&gt;

&lt;p&gt;Before ES6 in Javascript, You can declare variables by using &lt;strong&gt;var&lt;/strong&gt;, But the problem is var scope is &lt;strong&gt;global&lt;/strong&gt;, It has a chance to occur &lt;strong&gt;Name collision&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Const and Let introduce in &lt;strong&gt;ES6&lt;/strong&gt;, They come to solve to problem of var because of &lt;strong&gt;Block scope&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;They are used in different scenarios, Const is used when we don't want to change the value of variables and Let we can change the value of variables depending on the event.&lt;/p&gt;

&lt;p&gt;I think some of you are a little bit confusing because it has a lot of information, Let me show you the table to compare the differences between these three types of variables declaration. It will be easy to understand and apply to your implementations.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Declaration Type&lt;/th&gt;
&lt;th&gt;Scope&lt;/th&gt;
&lt;th&gt;Declaration&lt;/th&gt;
&lt;th&gt;Update value&lt;/th&gt;
&lt;th&gt;Re-declare&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;var&lt;/td&gt;
&lt;td&gt;globally, function&lt;/td&gt;
&lt;td&gt;Without initialize&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;const&lt;/td&gt;
&lt;td&gt;block&lt;/td&gt;
&lt;td&gt;Need initialize&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;let&lt;/td&gt;
&lt;td&gt;block&lt;/td&gt;
&lt;td&gt;Without initialize&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I will explain what happens above giving a comparison table. First, start from Scope.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scope
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Scope determines the accessibility (visibility) of variables. Or the level of accessibility and visibility of variables.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Contains 3 levels&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Block scope&lt;/li&gt;
&lt;li&gt;Function scope&lt;/li&gt;
&lt;li&gt;Global scope&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;before &lt;strong&gt;ES6&lt;/strong&gt; come, They have only Function scope and Global scope.&lt;/p&gt;

&lt;h3&gt;
  
  
  Declaration
&lt;/h3&gt;

&lt;p&gt;You need to initialize the value of variables when you declare if you used const, But no need for var and let.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update value
&lt;/h3&gt;

&lt;p&gt;If we need to change the value of a variable, We need to use var or let only.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips
&lt;/h3&gt;

&lt;p&gt;You have noticed each declaration has something different, You need to consider by a situation when to use var, const, or let. My suggestion is to use const or let for reduced the scope problem especially global scope from var, It will make a &lt;strong&gt;Name collision&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If something's wrong, incomplete or you want to share the experience. Please let me know in the comment.&lt;br&gt;
Thank you for taking the time to read this😘.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Var vs Const vs Let มันต่างกันยังไงนะ ?</title>
      <dc:creator>alternativeboy</dc:creator>
      <pubDate>Mon, 21 Feb 2022 05:40:35 +0000</pubDate>
      <link>https://dev.to/alternativeboy/lets-create-own-snippets-on-vscode-1co3</link>
      <guid>https://dev.to/alternativeboy/lets-create-own-snippets-on-vscode-1co3</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; ความแตกต่างของทั้งสามตัวนี้คือ Scope, Declaration, Update แล้วก็ Re-declaration นั้นเอง&lt;/p&gt;

&lt;h2&gt;
  
  
  เนื้อหา
&lt;/h2&gt;

&lt;p&gt;หลายคนเคยสงสัยไหมว่า เจ้า  var, const, let นั้นมันต่างกันยังไงทั้งๆที่จริงแล้วทั้งสามอย่างที่กล่าวมาสามารถใช้ประกาศตัวแปรได้ทั้งนั้น &lt;/p&gt;

&lt;p&gt;จริงๆแล้วมันมีที่มาเป็นอย่างงี้ครับ คือในช่วงแรกของ &lt;strong&gt;Javascript&lt;/strong&gt; นั้นการประกาศตัวแปรจะมีแค่ &lt;strong&gt;var&lt;/strong&gt; เท่านั้นแล้ว scope มันเป็น global ทำให้การ implement อะไรต่างๆค่อนข้างที่จำสับสนว่า ตัวแปรที่เรียกใช้นั้นเป็นของ file ที่เรากำลัง implement หรือเป็น file  อื่นนั้นเอง &lt;/p&gt;

&lt;p&gt;ทำให้ในยุคของ &lt;strong&gt;ES6&lt;/strong&gt; ได้เพิ่มการประกาศตัวแปรเพิ่มอีก 2 ชนิด คือ &lt;strong&gt;const กับ let&lt;/strong&gt; เจ้าสองตัวนี้เข้าช่วยให้การ development ง่ายขึ้นเพราะ block scope ของทั้งสองตัวนี้เป็น &lt;strong&gt;local&lt;/strong&gt; นั้นเอง แถมการเรียกใช้ก็แบ่งแยกชัดเจน const ใช้สำหรับตัวแปรที่หลังจากที่ initialize ค่าให้แล้วไม่อยากเปลี่ยนแปลงค่าของมันอีก ซึ่งแตกต่างกับ let ที่ เราอยากให้ค่ามันสามารถเปลี่ยนไปได้เรื่อยๆตาม usecase ที่เกิด &lt;/p&gt;

&lt;p&gt;คราวนี้หลายๆคนเริ่มสับสนแล้วว่าเราควรที่จะใช้การประกาศตัวแปรแบบไหนดี เดี๋ยวผมจะเอาตารางเปรียบเทียบมาให้ดูนะครับเพิ่อที่จะให้ง่ายต่อการนำไปใช้&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Declaration Type&lt;/th&gt;
&lt;th&gt;Scope&lt;/th&gt;
&lt;th&gt;Declaration&lt;/th&gt;
&lt;th&gt;Update value&lt;/th&gt;
&lt;th&gt;Re-declare&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;var&lt;/td&gt;
&lt;td&gt;globally, function&lt;/td&gt;
&lt;td&gt;Without initialize&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;const&lt;/td&gt;
&lt;td&gt;block&lt;/td&gt;
&lt;td&gt;Need initialize&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;let&lt;/td&gt;
&lt;td&gt;block&lt;/td&gt;
&lt;td&gt;Without initialize&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;ผมจะอธิบายตารางด้านบนให้นะครับเริิ่มจาก &lt;strong&gt;Scope&lt;/strong&gt; ก่อน&lt;/p&gt;

&lt;h3&gt;
  
  
  Scope
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Scope determines the accessibility (visibility) of variables. หรือก็คือการเข้าถึงของตัวแปรนั้นๆ ว่าสามารถเข้าถึงได้ระดับไหนนั้นเอง&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;จะประกอบไปด้วย 3 ระดับ&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Block scope&lt;/li&gt;
&lt;li&gt;Function scope&lt;/li&gt;
&lt;li&gt;Global scope&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ซึ่งเมื่อก่อน &lt;strong&gt;ES6&lt;/strong&gt; จะมามันมีแค่ Function scope กับ Global scope เท่านั้น &lt;/p&gt;

&lt;h3&gt;
  
  
  Declaration
&lt;/h3&gt;

&lt;p&gt;การกำหนดค่าตัวแปรขณะที่ประกาศตัวแปร อย่าง var กับ let ไม่จำเป็นที่จะต้องกำหนดค่าตัวแปรตอนประกาศก็ได้ แต่ว่า const นั้นจำเป็นที่จะต้องกำหนดต่าตัวแปรให้มัน&lt;/p&gt;

&lt;h3&gt;
  
  
  Update value
&lt;/h3&gt;

&lt;p&gt;ถ้าหากเราอยากเปลี่ยนค่าของตัวแปร เราสามารถใช้ var หรือ let เท่านั้น&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips
&lt;/h3&gt;

&lt;p&gt;จะสังเกตุได้ว่าแต่ละการประกาศตัวแปรจะมีบางอย่างที่แตกต่างกันขึ้นอยู่กับสถานการ์ที่เราจะนำไปใช้ แต่โดนส่วนตัวแล้วผมอยากแนะนำว่าใช้ const กับ let ดีกว่าเพื่อที่จะหมดปัญหาเรื่อง scope ที่บางทีชื่อตัวแปรของเราอาจจะซ้ำกันได้ทั้งใน file หรือ file อื่นๆ&lt;/p&gt;

&lt;p&gt;สามารถพูดคุยกันได้นะครับ บางอย่างผมอาจจะพูดไม่เคลียร์, ไม่เข้าใจ หรืออาจจะผิดพลาดตรงไหนก็ขอโทษด้วยนะครับผม หรืออยากจะเสริมเนื้อหาตรงจุดไหนแชร์มาได้เลยนะครับอยากแลกเปลี่ยนประสบกาณ์กับเพื่อนๆ แล้วเจอกันใหม่ในโพสต์หน้าครับ&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Let's create our snippets on  VSCode</title>
      <dc:creator>alternativeboy</dc:creator>
      <pubDate>Sun, 05 Sep 2021 10:30:14 +0000</pubDate>
      <link>https://dev.to/alternativeboy/let-s-create-our-snippets-on-vscode-4m79</link>
      <guid>https://dev.to/alternativeboy/let-s-create-our-snippets-on-vscode-4m79</guid>
      <description>&lt;p&gt;Hello, my friend today I'm gonna show you how to create your snippet on VSCode to improve your productivity.&lt;br&gt;
First of all, we need to understand what are "Code snippets"&lt;/p&gt;

&lt;p&gt;Code snippets are templates that make it easier to enter repeating code patterns. Or generate a boilerplate template for you by typing a keyword&lt;br&gt;
e.a if you typing &lt;code&gt;clg&lt;/code&gt; and hit tab or enter to confirm using a snippet then it will generate &lt;code&gt;console.log()&lt;/code&gt; immediately&lt;/p&gt;
&lt;h4&gt;
  
  
  Why do we need to create our snippets?
&lt;/h4&gt;

&lt;p&gt;Because of the snippets, we need sometimes they don't exist on Built-in Software or in the Marketplace. I decided to try to create, I found that it was easy to create. So I want to share this with you.&lt;/p&gt;
&lt;h4&gt;
  
  
  How to create Snippets on VSCode
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Open Command Pallet and type &lt;code&gt;Preferences: Configure User Snippets&lt;/code&gt; ( Shortcuts =&amp;gt; Window: Ctrl + Shift + P, Mac: CMD + Shift + P )&lt;/li&gt;
&lt;/ol&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%2Fvltk3ti1b6is9it8433e.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%2Fvltk3ti1b6is9it8433e.png" alt="Configure User Snippets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We can select which file we want to add our snippet to.  Today we gonna add to the javascript file.&lt;/li&gt;
&lt;/ol&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%2Fhe4zcnezwzdfmhstlzb5.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%2Fhe4zcnezwzdfmhstlzb5.png" alt="Select Snippet File"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example of our javascript snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log to the console"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'll explain what happens shows above. This snippet will generate 'console.log()' as you can see they have a JSON format.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the first line is the key of snippet&lt;/li&gt;
&lt;li&gt;a prefix is a snippet keyword to trigger&lt;/li&gt;
&lt;li&gt;the body is boilerplate we need, we can add a spacebar easily or write multiple lines.&lt;/li&gt;
&lt;li&gt;a description is a description of the snippet. It will describe which snippet we going to use e. a Log to the console will be shown on the right-hand side.&lt;/li&gt;
&lt;/ul&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%2Ftlrecj17epyf2nemg7o4.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%2Ftlrecj17epyf2nemg7o4.png" alt="Snippet Description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the snippet was successfully called the editor cursor will place inside a round bracket it will reduce our effort to move the cursor by ourselves. This is called Tabstops one of Snippet Syntax.&lt;/p&gt;

&lt;h4&gt;
  
  
  Snippet Syntax
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Tabstops: a Tabstops is moving the cursor inside generated snippet code. A Tabstops is using by type $ following by number 1, 2, 3, ... and so on the last number is 0. We can use the same number to edit multiple lines.&lt;/li&gt;
&lt;li&gt;Placeholder: a placeholder is a default value inside a generated snippet. A placeholder is using by typing ${} and a Tabstops number with  semicolon and placeholder value like this ${1:placeholderValue}
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        "body": [
            "const $1: ${2:string} = $3",
            "$0"
        ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the Tabstops two if we want 'string' we just skip this Tabstops by hit &lt;code&gt;Tab&lt;/code&gt;. So this is the benefit of placeholder.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choice: a choice is an option when we use inside a generated snippet
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        "body": [
            "const $1: ${2|string, number, boolean|} = $3",
            "$0"
        ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Variables: variables are built-in values to use inside a generated snippet. It using by type $VARIABLES_NAME on a snippet body.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        "body": [
            "const $1: ${2|string, number, boolean|} = $RANDOM",
            "$0"
        ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Available variables on VSCode following this &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Pros
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Reduce time to implement repetition code 
Good code style because code come from the same template snippet&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Code snippet can be duplicate on multiple files such as Built-in, Marketplace, or our snippets.
It takes time for writing good snippets for you because you need to refactor a snippet to fit in your situation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Code snippets cannot use when we're in the snippet editing process&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Bonus
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  These are some of the javascript snippets I'm using on my project.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First is generate an arrow function with a return value
"Create Arrow Function":{
      "prefix":"cf",
      "body":[
         "const $1 = (($2) =&amp;gt; {",
         "",
         "\t $0",
         "\treturn",
         "})"
      ],
      "description":"Create Arrow function"
    },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The other snippet generates an arrow function without a return value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Create Arrow Function without return": {
      "prefix":"cfn",
      "body":[
         "const $1 = (($2) =&amp;gt; {",
         "",
         "\t $0",
         "})"
      ],
      "description":"Create Arrow function without return"
    },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my first writing blog in English. I want to apologize if make you guys confusing in this post with my gramma. I will improve my English skills. Please let me know your thoughts comments below, I'm glad to receive any suggestions. See you in the next post. : ) &lt;/p&gt;

</description>
      <category>vscode</category>
      <category>snippet</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>มาเขียน Snippet ใช้เองกัน!!</title>
      <dc:creator>alternativeboy</dc:creator>
      <pubDate>Sun, 05 Sep 2021 09:27:29 +0000</pubDate>
      <link>https://dev.to/alternativeboy/snippet-5b88</link>
      <guid>https://dev.to/alternativeboy/snippet-5b88</guid>
      <description>&lt;p&gt;สวัสดีครับ วันนี้ผมจะมาสอนการสร้าง code snippet บน VSCode ที่จะช่วยเพิ่ม Productivity ในการ Implement code นั้นเอง &lt;br&gt;
ก่อนที่จะเริ่มเรามารู้จักเจ้า Code snippet กันก่อนดีกว่า&lt;/p&gt;

&lt;p&gt;Code snippet คืออะไร &lt;strong&gt;Code snippet เป็นการสร้างชุดโค้ดจากการเขียนสั้นๆ&lt;/strong&gt; &lt;br&gt;
ยกตัวอย่างเช่น การพิมพ์ &lt;code&gt;clg&lt;/code&gt; ถ้าหาก เรากด tab หรือ enter เพื่อ confirm ในการใช้ snippet นั้นจะเป็นการสร้าง &lt;code&gt;console.log()&lt;/code&gt; ขึ้นมา &lt;/p&gt;

&lt;p&gt;ทำไมเราถึงต้องเขียน snippet เอง เพราะว่า snippet ที่เราอยากได้นั้นมันอาจจะไม่มีใน Built-in หรือใน Marketplace หรือถึงจะมีก็ออกจะหายากไปหน่อย&lt;br&gt;
เลยตัดสินใจว่า เขียนเองเลยดีกว่าพอตอนเขียนก็รู้สึกว่าไม่ยากเกินไปเลยอยากจะมาแชร์ให้เพื่อนๆ&lt;/p&gt;

&lt;p&gt;โดยเจ้า Code snippet สามารถได้มาจาก 3 อย่างตามนี้&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Built-in VS Code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;VSCode snippets Marketplace ที่ได้มาจาก Plugin ที่เรา install นั้นเอง&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create own snippets หรือ snippet ที่เราเขียนขึ้นมาเองนั้นเอง&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  วิธีการสร้าง Snippet บน VSCode
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;เปิด Command Pallet ขึ้นแล้วพิมพ์คำว่า &lt;code&gt;Preferences: Configure User Snippets&lt;/code&gt; ( Shortcuts =&amp;gt; Window: Ctrl + Shift + P, Mac: CMD + Shift + P)&lt;/li&gt;
&lt;/ol&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%2Fvltk3ti1b6is9it8433e.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%2Fvltk3ti1b6is9it8433e.png" alt="Configure User Snippets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;เราสามารถเลือกได้ว่าจะเพิ่ม snippet ลงไฟล์ที่เป็นของเราเลย หรือ จะเพิ่มลงใน snippet ของแต่ละภาษาของ VS Code วันนี้เราจะมาเพิ่ม snippet ลงในไฟล์ VS Code กัน&lt;/li&gt;
&lt;/ol&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%2Fhe4zcnezwzdfmhstlzb5.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%2Fhe4zcnezwzdfmhstlzb5.png" alt="Select Snippet File"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ตัวอย่างที่จะเราจะเขียน Snippet วันนี้ขอเป็น ภาษา javascript ก็แล้วกัน&lt;/p&gt;

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

    "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log to the console"
    }


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

&lt;/div&gt;

&lt;p&gt;โดยผมจะอธิบายจากตัวอย่างด้านบนจะเป็น snippet การสร้าง console.log()&lt;br&gt;
จะสังเกตว่า มันเป็นลักษณะของ Json file format &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;บรรดทัดแรกเป็น key ของ snippet&lt;/li&gt;
&lt;li&gt;prefix คือ snippet ของเราว่าจะใช้ชื่ออะไร&lt;/li&gt;
&lt;li&gt;body ตัวคือสำคัญมากเพราะมันคือสิ่งที่เราอยากได้นั้นเอง เราเพิ่ม spacebar เข้าไปง่ายๆ หรือ การสร้างหลายๆบรรทัดโดยไม่ต้องใช้สัญลักษณ์พิเศษ &lt;/li&gt;
&lt;li&gt;description คือคำอธิบายว่า snippet ที่เรากำลังใช้งานนั้นเป็น snippet ของไฟล์ไหน อย่างเช่นตัวอย่างคือ Log to the console ที่จะอยู่ทางด้านขวามือ&lt;/li&gt;
&lt;/ul&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%2Ftlrecj17epyf2nemg7o4.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%2Ftlrecj17epyf2nemg7o4.png" alt="Snippet Description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;โดยเมื่อเราเรียกใช้เสร็จแล้ว editor cursor จะถูกไปวางในวงเล็บ เพื่อที่หลังจากเรา สร้าง snippet เราสามารถพิมพ์ด้านในวงเล็บได้เลย&lt;br&gt;
ทำให้เราไม่ต้องเลื่อน editor cursor เอง แล้วหลังจากที่เรากด Tab มันจะเป็นการเอา editor cursor ไปบรรทัดถัดนั้นเอง โดยสิ่งนี้เรียกว่า Tabstops หนึ่งใน Snippet Syntax&lt;/p&gt;

&lt;h4&gt;
  
  
  Snippet Syntax ของ body มีอยู่ 4 อย่าง ( เรียงจากความบ่อยในการเรียกใช้ )
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tabstops: tabstops คือการเลื่อนตัว editor cursor ใน snippet code ที่เราสร้างขึ้นมานั้นเอง โดยการใช้ tabstops นั้นจะต้องพิมพ์ $ แล้วตามด้วยตัวเลขอย่างเช่น $1, $2, ...   tabstops จะเริ่มจากเลข 1 แล้ว ตัวสุดท้ายคือเลข 0&lt;br&gt;
เราสามารถใข้ เลขเดียวซ้ำกันได้ ถ้าหากเราต้องการที่จะแก้ไขหลายๆจุดพร้อมกัน&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Placeholder : placeholder คือค่าการแทนค่าใน tabstops ด้วยค่า Default ของมัน ( placeholder)&lt;br&gt;
โดยการเขียน placehoder จะเป็น $ ตามด้วย ปีกกา {} ด้านในจะใส่ตัวเลขของ tabstops แล้วต่อด้วย placehoder คั้นด้วย : ( semi colon )&lt;br&gt;
${1:placeholder} อย่างเช่นการสร้าง field ใน model เราอาจจะสร้าง snippet ขึ้นมาตัว body เราอาจจะเขียนแบบนี้&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    "body": [
        "const $1: ${2:string} = $3",
        "$0"
    ],
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ซึ่งถ้าหากใน tabstops $2 เราอยากให้เป็น string เราก็แค่กด tab ไปมันจะใส่คำว่า string ให้เราเองเลยนี้คือข้อดีของ placeholder



* Choice: choice อีก syntax ที่มีประโยชน์แต่อาจจะใช้ได้น้อยสถานการณ์ choice เหมือน dropdown ที่มีตัวเลือกให้เราเลือก ถ้าหากสิ่งที่เราต้องการไม่มีอยู่ในตัวเลือกเราสามารถพิมพ์ได้ แต่อาจจะต้องกดออกจาก snippet edit process ด้วยการกด esc ก่อน
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "body": [
        "const $1: ${2|string, number, boolean|} = $3",
        "$0"
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
* Variables: การใช้ variables นั้นเราสามารถใช้ได้ด้วยการ $variableName หรือ ${variableName:default}
ซึ่งถ้า default ไม่มีค่าจะแทนที่ด้วย empty string ตัวอย่างของเราจะใช้ variableName ที่ชื่่อว่า random
ไอ่ตัว random จะเป็นการสุ่ม เลข 6 หลัก ฐาน10 ขึ้นมาให้เรา
"const $1 = $RANDOM ",
variableตัวอื่นที่สามารถใช้ได้สามารถดูได้จาก [link](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables) นี้เลย
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "body": [
        "const $1: ${2|string, number, boolean|} = $RANDOM",
        "$0"
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
###สรุป

####ข้อดีของการเขียน Snippets เอง
* ทำให้เราสามารถลดเวลาจากการเขียนโค้ดที่มีหน้าตาเหมือนๆกันได้
* code style จะออกมาใกล้เคียงกันเพราะสร้างมาจาก template snippet เดียวกัน

####แล้วข้อเสียหละ
* Code snippet จะอาจจะซ้ำกันได้ในหลายไฟล์ อย่างเช่น log อาจจะมาจาก Built-in, Marketplace plugin หรือว่ามาจากที่เราเขียน
ดังนั้นเราต้องเขียน description ให้เข้าใจง่ายเพื่อที่จะสามารถเรียกใช้ snippet ที่ถูกต้อง
* ใช้เวลาเขียน snippet file เพราะถ้าอยากได้ snippet ดีๆอาจจะต้องมีการ refactor หลายรอบ

####ข้อจำกัด
* Code snippet ไม่สามารถใช้ในได้ใน Code snippet ถ้ายังอยู่ใน snippet edit process

####ของแถม

อันนี้เป็นตัวอย่าง Snippets ที่ผมใช้จริงๆในฝั่ง Javascript นะครับ
อันแรกจเป็นการสร้าง Arrow Function ขึ้นมาแบบมี Return value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Create Arrow Function":{&lt;br&gt;
       "prefix":"cf",&lt;br&gt;
       "body":[&lt;br&gt;
          "const $1 = (($2) =&amp;gt; {",&lt;br&gt;
          "",&lt;br&gt;
          "\t $0",&lt;br&gt;
          "\treturn",&lt;br&gt;
          "})"&lt;br&gt;
       ],&lt;br&gt;
       "description":"Create Arrow function"&lt;br&gt;
    },&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
ส่วนอันที่สองก็เป็นการสร้าง Arrow Function เหมือนกันแต่ไม่มี Return value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Create Arrow Function without return": {&lt;br&gt;
       "prefix":"cfn",&lt;br&gt;
       "body":[&lt;br&gt;
          "const $1 = (($2) =&amp;gt;{",&lt;br&gt;
          "",&lt;br&gt;
          "\t $0",&lt;br&gt;
          "})"&lt;br&gt;
       ],&lt;br&gt;
       "description":"Create Arrow function without return"&lt;br&gt;
    },&lt;/p&gt;



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

ก่อนจากกันนี้ก็เป็นโพสต์แรกของผม ภาษาในการเขียนอาจจะยังเข้าใจยาก ถ้าหากมีตำแนะนำติชม คอมเมนต์กันมาเลยนะครับ แล้วเจอกันใหม่ในบทความหน้าครับผม : )

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

&lt;/div&gt;

</description>
      <category>vscode</category>
      <category>javascript</category>
      <category>productivity</category>
      <category>improvement</category>
    </item>
  </channel>
</rss>
