JavaScript Coding Day 6 | JavaScript : Symbol, Function, Object, Array, Date

JavaScript : Symbol, Function, Object, Array, Date

Watch the lesson tutorial  ðŸ”»

Here are the most common data types and structures you will use in JavaScript.

1. Symbol

A Symbol is a unique and immutable primitive value. It is often used to create unique identifiers for objects, ensuring that no two properties have the same key, even if they have the same description. Note that you call it as a function, without the new keyword.

Code Example:

<script>
  // A Symbol creates a unique identifier
  let e = Symbol("chirucodes");
  
  console.log(e);
</script>

Output:

Symbol(chirucodes)

2. Function

A Function is a block of code designed to perform a particular task. In JavaScript, functions are objects. In this example, we use a "Function Expression" where we store the function inside a variable.

Code Example:

<script>
  // A function that returns a value
  let f = function k() {
      return 10;
  };
  
  console.log(f());
</script>

Output:

10

3. Object

An Object is a collection of related data. It stores data in key-value pairs, where the key is a label (like name) and the value is the data (like "chirucodes"). It is created using curly braces { }.

Code Example:

<script>
  // An object stores key-value pairs
  let a = { name: "chirucodes" };
  
  console.log(a);
</script>

Output:

{ name: "chirucodes" }

4. Array

An Array is a special variable which can hold more than one value at a time. It is an ordered list, meaning the items stay in the order you put them in. Arrays are created using square brackets [ ].

Code Example:

<script>
  // An array stores a list of items
  let list = ['chirucodes'];
  
  console.log(list);
</script>

Output:

[ "chirucodes" ]

5. Date

The Date object is used to work with dates and times. To create a new date representing the current moment, you must use the new keyword followed by Date().

Code Example:

<script>
  // Creates a new Date object for the current time
  let n = new Date();
  
  console.log(n);
</script>

Output:

Thu Nov 20 2025 17:49:00 GMT+0800 (Singapore Standard Time)

(Note: This output will change based on your actual current time)



- by Chirana Nimnaka

Comments

Popular posts from this blog

Python Coding Day 1 | The print() Function and Comments

What is Python?

Set Up an Environment to Code in Python