Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
1. = = is an assignment operator in JavaScript, it is used to assign a value to a variable. e.g: const test = 1; console.log(test); // expected output: 1. In the above example, we have ass...
Answer
#3: Post edited
## 1. `=`.- `=` is an assignment operator in JavaScript, it is used to assign a value to a variable. e.g:
- ```js
- const test = 1;
- console.log(test);
- // expected output: 1.
- ```
- In the above example, we have assigned the value `1` to the variable `test` using the assignment operator `=`.
- Here is an another examples from MDN:
- ```
- const x = 2;
- const y = 3;
- console.log(x);
- // expected output: 2.
- console.log(x = y + 1); // 3 + 1
- // expected output: 4.
- console.log(x = x * y); // 4 * 3
- // expected output: 12.
- ```
- Learn more about `=` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment).
## 2. `==`.- `==` is a comparison operator in JavaScript, it attempts to convert and compare operands that are of different types,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(1 == 1);
- // expected output: true.
- ```
- In the above example, we compared `1`, which is a number, to other `1`, which is also a number, that mean the expected output will be `true`
- since they are the same type, we done this using the comparison operator `==`.
- Here is an another examples from MDN:
- ```js
- console.log('hello' == 'hello');
- // expected output: true.
- console.log(1 == "1");
- // expected output: true.
- console.log(0 == false);
- // expected output: true.
- ```
- Learn more about `==` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality).
## 3. `===`.- `===` is a strict equality comparison operator in JavaScript, it always considers operands of different types to be different,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(true === "true");
- // expected output: false.
- ```
- Since `===` considers operands of different types to be different, so `true` is considered `1` and `"true"` is considered `NaN`,
- so the expected output will be `false` since they different types, we done this using the strict equality comparison operator `===`.
- Here is an another examples from MDN:
- ```js
- console.log(1 === 1);
- // expected output: true.
- console.log('hello' === 'hello');
- // expected output: true.
- console.log('1' === 1);
- // expected output: false.
- console.log(0 === false);
- // expected output: false.
- ```
Learn more about `===` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).
- ## 1. `=`
- `=` is an assignment operator in JavaScript, it is used to assign a value to a variable. e.g:
- ```js
- const test = 1;
- console.log(test);
- // expected output: 1.
- ```
- In the above example, we have assigned the value `1` to the variable `test` using the assignment operator `=`.
- Here is an another examples from MDN:
- ```
- const x = 2;
- const y = 3;
- console.log(x);
- // expected output: 2.
- console.log(x = y + 1); // 3 + 1
- // expected output: 4.
- console.log(x = x * y); // 4 * 3
- // expected output: 12.
- ```
- Learn more about `=` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment).
- ## 2. `==`
- `==` is a comparison operator in JavaScript, it attempts to convert and compare operands that are of different types,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(1 == 1);
- // expected output: true.
- ```
- In the above example, we compared `1`, which is a number, to other `1`, which is also a number, that mean the expected output will be `true`
- since they are the same type, we done this using the comparison operator `==`.
- Here is an another examples from MDN:
- ```js
- console.log('hello' == 'hello');
- // expected output: true.
- console.log(1 == "1");
- // expected output: true.
- console.log(0 == false);
- // expected output: true.
- ```
- Learn more about `==` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality).
- ## 3. `===`
- `===` is a strict equality comparison operator in JavaScript, it always considers operands of different types to be different,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(true === "true");
- // expected output: false.
- ```
- Since `===` considers operands of different types to be different, so `true` is considered `1` and `"true"` is considered `NaN`,
- so the expected output will be `false` since they different types, we done this using the strict equality comparison operator `===`.
- Here is an another examples from MDN:
- ```js
- console.log(1 === 1);
- // expected output: true.
- console.log('hello' === 'hello');
- // expected output: true.
- console.log('1' === 1);
- // expected output: false.
- console.log(0 === false);
- // expected output: false.
- ```
- Learn more about `===` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).
- ## Summarize
- 1. `=` is an assignment operator.
- 2. `==` is a comparison operator.
- 3. `===` is a strict equality comparison operator.
#2: Post edited
- ## 1. `=`.
- `=` is an assignment operator in JavaScript, it is used to assign a value to a variable. e.g:
- ```js
- const test = 1;
- console.log(test);
- // expected output: 1.
- ```
- In the above example, we have assigned the value `1` to the variable `test` using the assignment operator `=`.
- Here is an another examples from MDN:
- ```
- const x = 2;
- const y = 3;
- console.log(x);
- // expected output: 2.
- console.log(x = y + 1); // 3 + 1
- // expected output: 4.
- console.log(x = x * y); // 4 * 3
- // expected output: 12.
- ```
- Learn more about `=` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment).
- ## 2. `==`.
- `==` is a comparison operator in JavaScript, it attempts to convert and compare operands that are of different types,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(1 == 1);
- // expected output: true.
- ```
- In the above example, we compared `1`, which is a number, to other `1`, which is also a number, that mean the expected output will be `true`
- since they are the same type, we done this using the comparison operator `==`.
- Here is an another examples from MDN:
- ```js
- console.log('hello' == 'hello');
- // expected output: true.
- console.log(1 == "1");
- // expected output: true.
- console.log(0 == false);
- // expected output: true.
- ```
- Learn more about `==` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality).
- ## 3. `===`.
- `===` is a strict equality comparison operator in JavaScript, it always considers operands of different types to be different,
returning a boolean result(`true` Or `false`). e.g:- ```js
- console.log(true === "true");
- // expected output: false.
- ```
- Since `===` considers operands of different types to be different, so `true` is considered `1` and `"true"` is considered `NaN`,
- so the expected output will be `false` since they different types, we done this using the strict equality comparison operator `===`.
- Here is an another examples from MDN:
- ```js
- console.log(1 === 1);
- // expected output: true.
- console.log('hello' === 'hello');
- // expected output: true.
- console.log('1' === 1);
- // expected output: false.
- console.log(0 === false);
- // expected output: false.
- ```
- Learn more about `===` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).
- ## 1. `=`.
- `=` is an assignment operator in JavaScript, it is used to assign a value to a variable. e.g:
- ```js
- const test = 1;
- console.log(test);
- // expected output: 1.
- ```
- In the above example, we have assigned the value `1` to the variable `test` using the assignment operator `=`.
- Here is an another examples from MDN:
- ```
- const x = 2;
- const y = 3;
- console.log(x);
- // expected output: 2.
- console.log(x = y + 1); // 3 + 1
- // expected output: 4.
- console.log(x = x * y); // 4 * 3
- // expected output: 12.
- ```
- Learn more about `=` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment).
- ## 2. `==`.
- `==` is a comparison operator in JavaScript, it attempts to convert and compare operands that are of different types,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(1 == 1);
- // expected output: true.
- ```
- In the above example, we compared `1`, which is a number, to other `1`, which is also a number, that mean the expected output will be `true`
- since they are the same type, we done this using the comparison operator `==`.
- Here is an another examples from MDN:
- ```js
- console.log('hello' == 'hello');
- // expected output: true.
- console.log(1 == "1");
- // expected output: true.
- console.log(0 == false);
- // expected output: true.
- ```
- Learn more about `==` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality).
- ## 3. `===`.
- `===` is a strict equality comparison operator in JavaScript, it always considers operands of different types to be different,
- returning a boolean result (`true` Or `false`). e.g:
- ```js
- console.log(true === "true");
- // expected output: false.
- ```
- Since `===` considers operands of different types to be different, so `true` is considered `1` and `"true"` is considered `NaN`,
- so the expected output will be `false` since they different types, we done this using the strict equality comparison operator `===`.
- Here is an another examples from MDN:
- ```js
- console.log(1 === 1);
- // expected output: true.
- console.log('hello' === 'hello');
- // expected output: true.
- console.log('1' === 1);
- // expected output: false.
- console.log(0 === false);
- // expected output: false.
- ```
- Learn more about `===` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).
#1: Initial revision
## 1. `=`. `=` is an assignment operator in JavaScript, it is used to assign a value to a variable. e.g: ```js const test = 1; console.log(test); // expected output: 1. ``` In the above example, we have assigned the value `1` to the variable `test` using the assignment operator `=`. Here is an another examples from MDN: ``` const x = 2; const y = 3; console.log(x); // expected output: 2. console.log(x = y + 1); // 3 + 1 // expected output: 4. console.log(x = x * y); // 4 * 3 // expected output: 12. ``` Learn more about `=` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment). ## 2. `==`. `==` is a comparison operator in JavaScript, it attempts to convert and compare operands that are of different types, returning a boolean result (`true` Or `false`). e.g: ```js console.log(1 == 1); // expected output: true. ``` In the above example, we compared `1`, which is a number, to other `1`, which is also a number, that mean the expected output will be `true` since they are the same type, we done this using the comparison operator `==`. Here is an another examples from MDN: ```js console.log('hello' == 'hello'); // expected output: true. console.log(1 == "1"); // expected output: true. console.log(0 == false); // expected output: true. ``` Learn more about `==` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality). ## 3. `===`. `===` is a strict equality comparison operator in JavaScript, it always considers operands of different types to be different, returning a boolean result(`true` Or `false`). e.g: ```js console.log(true === "true"); // expected output: false. ``` Since `===` considers operands of different types to be different, so `true` is considered `1` and `"true"` is considered `NaN`, so the expected output will be `false` since they different types, we done this using the strict equality comparison operator `===`. Here is an another examples from MDN: ```js console.log(1 === 1); // expected output: true. console.log('hello' === 'hello'); // expected output: true. console.log('1' === 1); // expected output: false. console.log(0 === false); // expected output: false. ``` Learn more about `===` at [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).