JavaScript Syntax
JavaScript Syntax profile { }, [ ], ( ) and more ...
Hello, my gorgeous friends on the internet ๐
Below are lists of JavaScript syntax with their information broken down into profile details and examples.
I hope you find this helpful, let's get started.
1. [ ]
English Name: Square Brackets
JavaScript Use: To declare an Array
Example ๐:
const favouriteFruits = [ "Mango", "Pawpaw", "Cashew" ];
2. { }
English Name: Curly brackets or braces
JavaScript Use: To create an Object Literal
Example ๐:
const favouriteBloggers = {
name: "Mr. Tapas",
site: "blog.greenroots.info"
}
3. ( )
English Name: Parentheses
JavaScript Use: To invoke functions or methods.
Example ๐:
const newFunction = ()=>{
// log() method
console.log("๐");
}
// Invoke function()
newFunction()
4. ...
English Name: 3 dots, full stops or periods
JavaScript Name: Spread Operator
JavaScript Use: To merge 2 or more arrays together
Example ๐:
const halfName = ["uncle"];
const otherhalfName = ["Bigbay"];
console.log(...arrayOfHalfName, ...otherHalfName)
Output ๐
5. ??
English Name: Question Marks
JavaScript Name: The nullish coalescing operator
JavaScript Use: To return the right-hand operand when the left-hand operand is null
or undefined
Example ๐:
const formField = null; // replace with a value
const formResponse = formField ?? "This Field is required";
console.log(formResponse);
6. &&
English Name: And
JavaScript Name: Logical AND
JavaScript Use: To return the right-hand operand when the left-hand operand is not "false"
Example ๐:
const isUserLoggedIn = true; // Change to false or string
const authenticationStatus = isUserLoggedIn && "Yes, ๐";
console.log(authenticationStatus);
7. ||
English Name: Vertical Bar
JavaScript Name: Logical OR
TypeScript Name: Double Pipe Operator
JavaScript Use: Returns true
if any of the conditions in an expression is true
.
Example ๐:
// Recruitment application ๐
const webDeveloper = true;
const hasExperience = false;
// Qualified if any of the condition is true
const qualified = webDeveloper || hasExperience;
if (qualified) {
console.log("You're welcome onboard ๐ค");
} else {
console.log("You are not one of us ๐ญ");
}
Output ๐
8. ? :
English Name: Unknown ๐
JavaScript Name: Ternary Operator
JavaScript Use: Alternative to if else
block
Example ๐:
const finalExamDay = 19;
// If final exam day is zero, I am happy else I really don't enjoy school
const mood = finalExamDay === 0 ? "Happy, coding time ๐" : "I hate school ๐ฅ";
console.log(mood);
Output ๐
9. ++ Operand
English Name: Plus Sign
JavaScript Name: Increment
JavaScript Use: To increase its operand by one (1) and return a new value
Example ๐
let point = 0;
const makePoint = ++point;
console.log(makePoint);
Output ๐
10. -- Operand
English Name: Minus Sign
JavaScript Name: Decrement
JavaScript Use: To deduct one (1) from its operand and return a new value
Example ๐
let point = 1;
const losePoint = --point;
console.log(losePoint);
Output ๐
Wow, what a journey, I am glad you made it to the end of this article, if you enjoyed and learned something new from this article, you can subscribe to my newsletter to get notified of my upcoming articles.
I will also like to connect with you, let's connect on:
See you in the next article. Bye Bye ๐โโ๏ธ
If you found my content helpful and would want to support my blog, you can support me by buying me a coffee below, my blog lives on coffee ๐.